SlideShare a Scribd company logo
Array
Topics
 Array
 Dimension of Array
 Array initialization
 Multidimensional array
Array
 Array: An array is a group of related data
items that share a common name. A
particular value is indicated by writing a
number called index number or subscript in
brackets after array name. For example:
info[100] represent 100th
information.
 While the complete set of values is referred
to as an array, the individual values are
called elements. Arrays can be of any data
type.
One Dimensional Array
 A list of items can be given one variable
name using only one subscript and such a
variable is called a one dimensional array.
 In C, one dimensional can be represented
as: x[1], x[2], …….x[n]
 The subscript can begin with number 0. That
is x[0] is allowed.
 Declaration of Array:
data_type var_name[size];
Continue..
 Ex: int x[10]; declares x as a one
dimensional array which can contain
maximum 10 integer numbers. The
subscript can from 0 to 9.
 C language treats character strings simply
as arrays of characters.
 Ex: char name[10]; declares the name as a
character array (string) variable that can
hold a maximum of 10 characters.
Continue…
 Initialization of Arrays: Like the ordinary variable
we can initialize the elements of arrays at the time
of declaration.
 General form:
static type var_name[size]={list of values};
 The values in the list are separated by commas.
Ex: static int x[5]={1,5,6,10,7};
 If the number of values in the list is less than the
number of elements, then only that many elements
will be initialized. The remaining elements will be
set to zero automatically.
 Ex: static int x[5]={10, 5, 15}; will initialize the first
three elements to 10, 5, 15 and the remaining two
elements to zero.
Continue..
 The size may be omitted.
 Ex: static int x[ ] ={1,2,3,4};
 Character arrays may be initialized in a
similar manner. Thus the statement:
static char name[ ]= {‘T’,’O’,’M’};
Two dimensional Array
 C allows us to define tables (which has row
and column) of items by using two
dimensional array. General form:
type array_name[row_size][col_size];
 Ex: int num[10][5]; declares a variable num
of 10 rows and 5 columns that is 50 values
can be stored in the array. Each value can
be accessed by using two subscripts (row
number and column number).
 So num[4][2] mean the 3rd element in the 5th
row of the array num.
Initializing two dimensional Array
 Two-dimensional arrays may be initialized
by following their declaration with a list of
initial values enclosed in braces.
 Ex: static int table[3][2]={0,0,1,1,2,2};
initialize the elements to the first row to 0, 2nd
row to 1 and 3rd
row to 2.
 The initialization is done row by row.
Ex: static int table[3][2]={{0,0},{1,1},{2,2}};
 When all the elements are to be initialized to
zero, we can write:
static int table[3][5]={{0},{0},{0}};
Multidimensional Array
 C allows arrays of three or more
dimensions. The general form is:
type array_name[s1][s2]……[sn]; where si is
the size of the ith dimension.
 Ex: int x[5][4][6];
float y[5][5][4][3];
Program for average of N numbers
#define N 10
main()
{
int k, x[10], total=0;
float avg;
for(k=0;k<N;k++)
scanf(“%d”,&x[k]);
for(k=0;k<N;k++)
total = total+x[k];
avg=(float)total/N;
printf(“Average = %f”, avg);
}

More Related Content

What's hot

arrays in c
arrays in carrays in c
arrays in c
vidhi mehta
 
Arrays
ArraysArrays
ARRAY
ARRAYARRAY
ARRAY
ayush raj
 
Array
ArrayArray
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
Satyam Soni
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
Gurpreet singh
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Array
ArrayArray
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
Gurpreet singh
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
arushi bhatnagar
 
Arrays
ArraysArrays
Arrays
sana younas
 
Array
ArrayArray
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
tanmaymodi4
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
mJafarww
 

What's hot (19)

arrays in c
arrays in carrays in c
arrays in c
 
Arrays
ArraysArrays
Arrays
 
ARRAY
ARRAYARRAY
ARRAY
 
Array
ArrayArray
Array
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Array
ArrayArray
Array
 
Array in c
Array in cArray in c
Array in c
 
Array
ArrayArray
Array
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
 

Viewers also liked

2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
Education Front
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
Smit Parikh
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Arrays
ArraysArrays
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Algorithm and Programming (Array)
Algorithm and Programming (Array)Algorithm and Programming (Array)
Algorithm and Programming (Array)
Adam Mukharil Bachtiar
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
indra Kishor
 

Viewers also liked (10)

Gui
GuiGui
Gui
 
Ppt lesson 12
Ppt lesson 12Ppt lesson 12
Ppt lesson 12
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Algorithm and Programming (Array)
Algorithm and Programming (Array)Algorithm and Programming (Array)
Algorithm and Programming (Array)
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
 

Similar to Chap 7(array)

lec 2- array declaration and initialization.pptx
lec 2- array declaration and initialization.pptxlec 2- array declaration and initialization.pptx
lec 2- array declaration and initialization.pptx
shiks1234
 
ARRAYS
ARRAYSARRAYS
ARRAYS
muniryaseen
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
Uma mohan
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Arrays in C Programming
Arrays in C ProgrammingArrays in C Programming
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
FolkAdonis
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
Array in-c
Array in-cArray in-c
Array in-c
Samsil Arefin
 
Array in c language
Array in c language Array in c language
Array in c language
umesh patil
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Array in C
Array in CArray in C
Array in C
adityas29
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 

Similar to Chap 7(array) (20)

lec 2- array declaration and initialization.pptx
lec 2- array declaration and initialization.pptxlec 2- array declaration and initialization.pptx
lec 2- array declaration and initialization.pptx
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Comp102 lec 8
Comp102   lec 8Comp102   lec 8
Comp102 lec 8
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Arrays
ArraysArrays
Arrays
 
Arrays in C Programming
Arrays in C ProgrammingArrays in C Programming
Arrays in C Programming
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
2 arrays
2   arrays2   arrays
2 arrays
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Array in-c
Array in-cArray in-c
Array in-c
 
Array in c language
Array in c language Array in c language
Array in c language
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Arrays
ArraysArrays
Arrays
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Array in C
Array in CArray in C
Array in C
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

Chap 7(array)

  • 1. Array Topics  Array  Dimension of Array  Array initialization  Multidimensional array
  • 2. Array  Array: An array is a group of related data items that share a common name. A particular value is indicated by writing a number called index number or subscript in brackets after array name. For example: info[100] represent 100th information.  While the complete set of values is referred to as an array, the individual values are called elements. Arrays can be of any data type.
  • 3. One Dimensional Array  A list of items can be given one variable name using only one subscript and such a variable is called a one dimensional array.  In C, one dimensional can be represented as: x[1], x[2], …….x[n]  The subscript can begin with number 0. That is x[0] is allowed.  Declaration of Array: data_type var_name[size];
  • 4. Continue..  Ex: int x[10]; declares x as a one dimensional array which can contain maximum 10 integer numbers. The subscript can from 0 to 9.  C language treats character strings simply as arrays of characters.  Ex: char name[10]; declares the name as a character array (string) variable that can hold a maximum of 10 characters.
  • 5. Continue…  Initialization of Arrays: Like the ordinary variable we can initialize the elements of arrays at the time of declaration.  General form: static type var_name[size]={list of values};  The values in the list are separated by commas. Ex: static int x[5]={1,5,6,10,7};  If the number of values in the list is less than the number of elements, then only that many elements will be initialized. The remaining elements will be set to zero automatically.  Ex: static int x[5]={10, 5, 15}; will initialize the first three elements to 10, 5, 15 and the remaining two elements to zero.
  • 6. Continue..  The size may be omitted.  Ex: static int x[ ] ={1,2,3,4};  Character arrays may be initialized in a similar manner. Thus the statement: static char name[ ]= {‘T’,’O’,’M’};
  • 7. Two dimensional Array  C allows us to define tables (which has row and column) of items by using two dimensional array. General form: type array_name[row_size][col_size];  Ex: int num[10][5]; declares a variable num of 10 rows and 5 columns that is 50 values can be stored in the array. Each value can be accessed by using two subscripts (row number and column number).  So num[4][2] mean the 3rd element in the 5th row of the array num.
  • 8. Initializing two dimensional Array  Two-dimensional arrays may be initialized by following their declaration with a list of initial values enclosed in braces.  Ex: static int table[3][2]={0,0,1,1,2,2}; initialize the elements to the first row to 0, 2nd row to 1 and 3rd row to 2.  The initialization is done row by row. Ex: static int table[3][2]={{0,0},{1,1},{2,2}};  When all the elements are to be initialized to zero, we can write: static int table[3][5]={{0},{0},{0}};
  • 9. Multidimensional Array  C allows arrays of three or more dimensions. The general form is: type array_name[s1][s2]……[sn]; where si is the size of the ith dimension.  Ex: int x[5][4][6]; float y[5][5][4][3];
  • 10. Program for average of N numbers #define N 10 main() { int k, x[10], total=0; float avg; for(k=0;k<N;k++) scanf(“%d”,&x[k]); for(k=0;k<N;k++) total = total+x[k]; avg=(float)total/N; printf(“Average = %f”, avg); }