SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and UnionsDhrumil Patel
 
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
 
Presentation on array
Presentation on array Presentation on array
Presentation on array topu93
 
Array in Java
Array in JavaArray in Java
Array in JavaAli shah
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programmingRumman Ansari
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialKuntal Bhowmick
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in javaHitesh Kumar
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
String in c programming
String in c programmingString in c programming
String in c programmingDevan Thakur
 

Was ist angesagt? (20)

C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Enums in c
Enums in cEnums in c
Enums in c
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Strings in C
Strings in CStrings in C
Strings in C
 
C# basics
 C# basics C# basics
C# basics
 
String in c programming
String in c programmingString in c programming
String in c programming
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie 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
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Array
ArrayArray
Array
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 

Kürzlich hochgeladen

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
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
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 

Kürzlich hochgeladen (20)

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
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
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
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...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

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];