SlideShare uma empresa Scribd logo
1 de 17
ARRAYS IN C LANGUAGE
Aditya Silver Oak Institute of Technology
• Name : Surbhi R Yadav
• Branch : Computer Engineering
• Enroll. No.: 141200107065
• Subject Name : Computer Programming and
Utilization
• Date : 03/03/2015
Contents
• Need of an Arrays
• Introduction
• Types of Arrays
• Single dimensional Arrays
• Two dimensional Arrays
• Multi-dimensional Arrays
Need of an Array
• Till now, we have been storing data in simple
variables.
• Although storing data of a large number of
people is quite difficult with the process we use
still.
• To store this large data, the developers
developed the concept of arrays in C language
Introduction
• An array is a collection of similar data elements
with same data type
• The elements of the array are stored in
consecutive memory locations and are
referenced by an index.
• Index indicates an ordinal number of the
elements counted from beginning of the array.
Some examples where the concept of the array can be
used are :
• List of temperatures recorded on every day of month
• List of employees in a company
• List of students in a class
• List of products sold
• List of customers
Arrays are of three types :
• Single dimensional Array
• Two-dimensional Array
• Multi-dimensional Array
Single dimensional Array
• The one dimensional array or single dimensional
array in C language is the simplest type of array
that contains only one row for storing data.
• One dimensional array is like a list of some
items, which can be stored by using only one
dimension.
Declaration of Array
• An array must be declared before being used
• Declaring an array means specifying three things
o Data type-what kind of values it can store, like
int, char, float, double
oName-to identify the array
oSize-the maximum number of values that array
can hold
oSyntax : datatype variablename[size] ;
oEx : int marks[10];
Initialization of Arrays
• Elements of the array can also be initialized at
the time of declaration as in the case of every
variable.
• Arrays are initialized as :
datatype array_name[size]={list of values};
Ex : int a[5]={90,82,78,95,88};
a[0] a[1] a[2] a[3] a[4]
90 82 78 95 88
Operations that can be performed on
Arrays
There are number of operations that can be
performed on arrays. These operations include :
• Transversal
• Insertion
• Search
• Deletion
• Merging
• Sorting
Example of One Dimensional Array
• /*Write a program to get n numbers and find out sum and average of numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10]; //array of size 10
int i,n;
float avg,sum=0;
clrscr();
printf(“Give the values of n”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“Give numbern”);
scanf(“%d”,&a[i]);
sum=sum+a[i];
}
avg=sum/n;
printf(“Array elements are :n);
for(i=0;i<n;i++)
printf(“nSum=%f Average= %6.2fn”,sum, avg);
}
Two Dimensional Array
• If one dimensional array is like a list, two
dimensional array is like a table.
• A two dimensional array is specified using two
index where one denotes row and another one
denotes column.
• C considers the two dimensional array as an
array of a one dimensional array.
Declaration of Two Dimensional Array
• Similar to one dimensional arrays, two
dimensional arrays must be declared before
being used.
• A two dimensional array is declared as :
data_type array_name[rowsize][columnsize];
Ex :
int marks[3][5];
Initialization of Two-Dimensional Array
• A two-dimensional array is initialized in the same
way as a one-dimensional array.
• Ex : int a[2][3] = {90,87,78,68,62,71};
or
int a[2][3] = {{90,87,78},{68,62,71}};
a[0][0] a[0][1] a[0][2]
90 87 78
68 62 71
a[1][0] a[1][1] a[1][2]
• /*Write a program to read 3*3 matrix and find maximum number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j,max;
clrscr();
printf(“How matrix row wisen”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“a[%d][%d]= “,i,j);
scanf(“%d”,&[i][j]);
}
printf(“n”);
}
max=a[0][0];
for(i=0;i<3;i++)
{
for(j=o;j<3;j++)
{
if(max<a[i][j])
max=a[i][j];
}
}
printf(“Max number is = %d”,max);
getch();
}
Multi-dimensional Array
• In general, we can have n-dimensional array.
• If n>=2, then we call that array as multi-
dimensional array. For example, suppose we
want to store 5 students marks information for
two different exams carried out in the term for 4
different subjects, this data can be stored by
using 3-dimensional array like,
int marks[5][2][4];
Arrays In C Language

Mais conteúdo relacionado

Mais procurados

Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c languagetanmaymodi4
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array dincyjain
 
Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Listsprimeteacher32
 
Presentation on array
Presentation on array Presentation on array
Presentation on array topu93
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D arraySangani Ankur
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programmingSajid Hasan
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 

Mais procurados (20)

2D Array
2D Array 2D Array
2D Array
 
ARRAY
ARRAYARRAY
ARRAY
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Array in C
Array in CArray in C
Array in C
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
 
Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Lists
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Array in c++
Array in c++Array in c++
Array in c++
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Arrays
ArraysArrays
Arrays
 
Data Types In C
Data Types In CData Types In C
Data Types In C
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 

Destaque (16)

Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Arrays
ArraysArrays
Arrays
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture Notes
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
C string
C stringC string
C string
 
Functions in C
Functions in CFunctions in C
Functions in C
 
String in c
String in cString in c
String in c
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Array in C
Array in CArray in C
Array in C
 
Function in c
Function in cFunction in c
Function in c
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Function in C program
Function in C programFunction in C program
Function in C program
 

Semelhante a Arrays In C Language (20)

Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Arrays
ArraysArrays
Arrays
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
BHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptxBHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptx
 
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
 
Array
ArrayArray
Array
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Arrays
ArraysArrays
Arrays
 
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Array
ArrayArray
Array
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 

Último

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 

Último (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 

Arrays In C Language

  • 1. ARRAYS IN C LANGUAGE
  • 2. Aditya Silver Oak Institute of Technology • Name : Surbhi R Yadav • Branch : Computer Engineering • Enroll. No.: 141200107065 • Subject Name : Computer Programming and Utilization • Date : 03/03/2015
  • 3. Contents • Need of an Arrays • Introduction • Types of Arrays • Single dimensional Arrays • Two dimensional Arrays • Multi-dimensional Arrays
  • 4. Need of an Array • Till now, we have been storing data in simple variables. • Although storing data of a large number of people is quite difficult with the process we use still. • To store this large data, the developers developed the concept of arrays in C language
  • 5. Introduction • An array is a collection of similar data elements with same data type • The elements of the array are stored in consecutive memory locations and are referenced by an index. • Index indicates an ordinal number of the elements counted from beginning of the array.
  • 6. Some examples where the concept of the array can be used are : • List of temperatures recorded on every day of month • List of employees in a company • List of students in a class • List of products sold • List of customers Arrays are of three types : • Single dimensional Array • Two-dimensional Array • Multi-dimensional Array
  • 7. Single dimensional Array • The one dimensional array or single dimensional array in C language is the simplest type of array that contains only one row for storing data. • One dimensional array is like a list of some items, which can be stored by using only one dimension.
  • 8. Declaration of Array • An array must be declared before being used • Declaring an array means specifying three things o Data type-what kind of values it can store, like int, char, float, double oName-to identify the array oSize-the maximum number of values that array can hold oSyntax : datatype variablename[size] ; oEx : int marks[10];
  • 9. Initialization of Arrays • Elements of the array can also be initialized at the time of declaration as in the case of every variable. • Arrays are initialized as : datatype array_name[size]={list of values}; Ex : int a[5]={90,82,78,95,88}; a[0] a[1] a[2] a[3] a[4] 90 82 78 95 88
  • 10. Operations that can be performed on Arrays There are number of operations that can be performed on arrays. These operations include : • Transversal • Insertion • Search • Deletion • Merging • Sorting
  • 11. Example of One Dimensional Array • /*Write a program to get n numbers and find out sum and average of numbers*/ #include<stdio.h> #include<conio.h> void main() { int a[10]; //array of size 10 int i,n; float avg,sum=0; clrscr(); printf(“Give the values of n”); scanf(“%d”,&n); for(i=0;i<n;i++) { printf(“Give numbern”); scanf(“%d”,&a[i]); sum=sum+a[i]; } avg=sum/n; printf(“Array elements are :n); for(i=0;i<n;i++) printf(“nSum=%f Average= %6.2fn”,sum, avg); }
  • 12. Two Dimensional Array • If one dimensional array is like a list, two dimensional array is like a table. • A two dimensional array is specified using two index where one denotes row and another one denotes column. • C considers the two dimensional array as an array of a one dimensional array.
  • 13. Declaration of Two Dimensional Array • Similar to one dimensional arrays, two dimensional arrays must be declared before being used. • A two dimensional array is declared as : data_type array_name[rowsize][columnsize]; Ex : int marks[3][5];
  • 14. Initialization of Two-Dimensional Array • A two-dimensional array is initialized in the same way as a one-dimensional array. • Ex : int a[2][3] = {90,87,78,68,62,71}; or int a[2][3] = {{90,87,78},{68,62,71}}; a[0][0] a[0][1] a[0][2] 90 87 78 68 62 71 a[1][0] a[1][1] a[1][2]
  • 15. • /*Write a program to read 3*3 matrix and find maximum number*/ #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j,max; clrscr(); printf(“How matrix row wisen”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“a[%d][%d]= “,i,j); scanf(“%d”,&[i][j]); } printf(“n”); } max=a[0][0]; for(i=0;i<3;i++) { for(j=o;j<3;j++) { if(max<a[i][j]) max=a[i][j]; } } printf(“Max number is = %d”,max); getch(); }
  • 16. Multi-dimensional Array • In general, we can have n-dimensional array. • If n>=2, then we call that array as multi- dimensional array. For example, suppose we want to store 5 students marks information for two different exams carried out in the term for 4 different subjects, this data can be stored by using 3-dimensional array like, int marks[5][2][4];