SlideShare a Scribd company logo
ARRAYS IN C
INTRODUCTION
• We know the fundamental data types, namely
char, int, float, double and it’s variations.
• Although these types are very useful, the
variable of these types can store only one value
at a given time.
• Therefore, these data types can be used only to
handle limited amounts of data.
• In many applications we need handle large
volume of data for processing.
• To process such large amounts of data we need
a powerful data type.
DEFINITION OF ARRAY
• An array is a fixed–size sequenced collection of
elements of same data type
• In simplest form, an array can be used to
represent a list of numbers, a list of names.
• An array is a collection of similar data items,
that are stored under a common name.
• A value in an array is identified by index or
subscript enclosed in square bracket with array
name.
FEATURES OF ARRAYS
• An array is a derived data type. It is used to
represent a collection of elements of the same
data type.
• The elements can be accessed with base
address (index) and the subscript defined for
the position of the element.
• The elements in an array are stored in
contiguous memory location.
• It is easier to refer the array elements by simply
incrementing the value of the subscript.
TYPES OF ARRAYS
1. One dimensional array
2. Two dimensional array
3. Multidimensional array
ONE DIMENSIONAL ARRAY
The collection of data items can be
stored under a variable name using only
one subscript
ARRAY DECLARATION
The general form of array declaration is:
data_type array_variable-name[size];
• Data_type – specifies the type of element that
will be contained in the array , such as int, char
• size –indicates the maximum number of
elements that can be stored inside the array.
EXAMPLE
• For example we want to represent a set of five numbers,
say (10,20,30,40,50) by an array variable number, then we
may declare the variable number as follows
int number[5];
• and the computer reserves five storage locations as shown
below:
Number[0]
Number[1]
Number[2]
Number[3]
Number[4]
ARRAY INTIALIZATION
Syntax:
data_type array_variable-name[SIZE]={LIST OF VALUE}
EXAMPLE :
int number[5]={10,20,30,40,50};
Number[0]
Number[1]
Number[2]
Number[3]
Number[4]
fv
10
20
30
40
50
MORE EXAMPLES FOR ARRAY INITIALIZATION
int counter[ ]= {10,20,30,40,50};
char name[ ]= { ’J’ , ’H’ , ’O’ , ’N’ , ’0” };
alternatively,
char name[ ]= “john”; //array with string
int number[5]={10,20};
number[0]=10,number[1]=20,
number[2]=0,number[3]=0,number[4]=0
• we can also initialize an array with scanf() function.
for example,
int x[5];
printf(“enter the values:”);
scanf(“%d%d%d”,&x[0],&x[1],&x[2]);
EXAMPLE PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],sum=0,i;
printf(“Enter 5 numbers”);
for(i=0;i<5;i++)
{
scanf(“%dn”,&a[i]);
sum=sum+a[i];
}
printf(“the sum of given numbers is : %dn”, sum);
}
TWO DIMENSIONAL ARRAY
SYNTAX:
data_type array_name [row-size][column-size];
INITIAZING TWO DIMENSIONAL ARRAY:
Like one dimensional arrays, two dimensional arrays can be
initialized by their declaration
int table[2][3] = {0,0,0,1,1,1};
will assigns the values as follows,
table[0][1]=0, table[0][1]=0, table[0][2]=0,
table[1][0]=1, table[1][1]=1, table[1][2]=1
the above statement can be written as
int table[2][3]={{0,0,0},{1,1,1}};
also
int table[2][3] = {
{0,0,0},
{1,1,1}
};
Example program
#include <stdio.h>
main()
{
int m, n, i, j, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrix ");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrixn");
for ( i = 0 ; i< m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &first[i][j]);
printf("Enter the elements of second matrixn");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &second[i][j]);
for ( i= 0 ; i < m ; i++ )
for ( j = 0 ; j< n ; j++ )
sum[i][j] = first[i][j] + second[i][j];
printf("Sum of entered matrices:-n");
for ( i= 0 ; i< m ; i++ )
{
for ( j = 0 ; j < n ; j++ )
printf("%dt", sum[i][j]);
printf("n");
}
return 0;
}
MULTI-DIMENSIONAL ARRAY
C allows arrays of more-dimensions called multi-
dimensional array.
The general form of a multi-dimensional array is:
Type array-name[s1][s2][s3]…..[sn]
Where ‘s’ is the size of the dimension
int survey[3][5][2];
float table[5][4][5][3];
Ad

More Related Content

What's hot (20)

Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Arrays in c
Arrays in cArrays in c
Arrays in c
vampugani
 
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
imtiazalijoono
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
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
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Arrays
ArraysArrays
Arrays
Trupti Agrawal
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
dincyjain
 
structure and union
structure and unionstructure and union
structure and union
student
 
Strings
StringsStrings
Strings
Mitali Chugh
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
String functions in C
String functions in CString functions in C
String functions in C
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
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
imtiazalijoono
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
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
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
dincyjain
 
structure and union
structure and unionstructure and union
structure and union
student
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 

Similar to Arrays in c (20)

BHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptxBHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptxChyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
RobertCarreonBula
 
uderstanding arrays and how to declare arrays
uderstanding arrays and how to declare arraysuderstanding arrays and how to declare arrays
uderstanding arrays and how to declare arrays
ShirishaBuduputi
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
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 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
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Arrays
ArraysArrays
Arrays
Notre Dame of Midsayap College
 
Array
ArrayArray
Array
PreethyJemima
 
Arrays
ArraysArrays
Arrays
swathi reddy
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
lakshmanarao027MVGRC
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
Array in c
Array in cArray in c
Array in c
Harsh Bhanushali
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
Chapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdfChapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdf
KirubelWondwoson1
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Maliha Mehr
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
Mohit750936
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
MamataAnilgod
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Ad

Recently uploaded (20)

Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
Ad

Arrays in c

  • 2. INTRODUCTION • We know the fundamental data types, namely char, int, float, double and it’s variations. • Although these types are very useful, the variable of these types can store only one value at a given time. • Therefore, these data types can be used only to handle limited amounts of data. • In many applications we need handle large volume of data for processing. • To process such large amounts of data we need a powerful data type.
  • 3. DEFINITION OF ARRAY • An array is a fixed–size sequenced collection of elements of same data type • In simplest form, an array can be used to represent a list of numbers, a list of names. • An array is a collection of similar data items, that are stored under a common name. • A value in an array is identified by index or subscript enclosed in square bracket with array name.
  • 4. FEATURES OF ARRAYS • An array is a derived data type. It is used to represent a collection of elements of the same data type. • The elements can be accessed with base address (index) and the subscript defined for the position of the element. • The elements in an array are stored in contiguous memory location. • It is easier to refer the array elements by simply incrementing the value of the subscript.
  • 5. TYPES OF ARRAYS 1. One dimensional array 2. Two dimensional array 3. Multidimensional array ONE DIMENSIONAL ARRAY The collection of data items can be stored under a variable name using only one subscript
  • 6. ARRAY DECLARATION The general form of array declaration is: data_type array_variable-name[size]; • Data_type – specifies the type of element that will be contained in the array , such as int, char • size –indicates the maximum number of elements that can be stored inside the array.
  • 7. EXAMPLE • For example we want to represent a set of five numbers, say (10,20,30,40,50) by an array variable number, then we may declare the variable number as follows int number[5]; • and the computer reserves five storage locations as shown below: Number[0] Number[1] Number[2] Number[3] Number[4]
  • 8. ARRAY INTIALIZATION Syntax: data_type array_variable-name[SIZE]={LIST OF VALUE} EXAMPLE : int number[5]={10,20,30,40,50}; Number[0] Number[1] Number[2] Number[3] Number[4] fv 10 20 30 40 50
  • 9. MORE EXAMPLES FOR ARRAY INITIALIZATION int counter[ ]= {10,20,30,40,50}; char name[ ]= { ’J’ , ’H’ , ’O’ , ’N’ , ’0” }; alternatively, char name[ ]= “john”; //array with string int number[5]={10,20}; number[0]=10,number[1]=20, number[2]=0,number[3]=0,number[4]=0 • we can also initialize an array with scanf() function. for example, int x[5]; printf(“enter the values:”); scanf(“%d%d%d”,&x[0],&x[1],&x[2]);
  • 10. EXAMPLE PROGRAM #include<stdio.h> #include<conio.h> void main() { int a[5],sum=0,i; printf(“Enter 5 numbers”); for(i=0;i<5;i++) { scanf(“%dn”,&a[i]); sum=sum+a[i]; } printf(“the sum of given numbers is : %dn”, sum); }
  • 11. TWO DIMENSIONAL ARRAY SYNTAX: data_type array_name [row-size][column-size]; INITIAZING TWO DIMENSIONAL ARRAY: Like one dimensional arrays, two dimensional arrays can be initialized by their declaration int table[2][3] = {0,0,0,1,1,1}; will assigns the values as follows, table[0][1]=0, table[0][1]=0, table[0][2]=0, table[1][0]=1, table[1][1]=1, table[1][2]=1 the above statement can be written as int table[2][3]={{0,0,0},{1,1,1}}; also int table[2][3] = { {0,0,0}, {1,1,1} };
  • 12. Example program #include <stdio.h> main() { int m, n, i, j, first[10][10], second[10][10], sum[10][10]; printf("Enter the number of rows and columns of matrix "); scanf("%d%d", &m, &n); printf("Enter the elements of first matrixn"); for ( i = 0 ; i< m ; i++ ) for ( j = 0 ; j < n ; j++ ) scanf("%d", &first[i][j]); printf("Enter the elements of second matrixn"); for ( i = 0 ; i < m ; i++ ) for ( j = 0 ; j < n ; j++ ) scanf("%d", &second[i][j]);
  • 13. for ( i= 0 ; i < m ; i++ ) for ( j = 0 ; j< n ; j++ ) sum[i][j] = first[i][j] + second[i][j]; printf("Sum of entered matrices:-n"); for ( i= 0 ; i< m ; i++ ) { for ( j = 0 ; j < n ; j++ ) printf("%dt", sum[i][j]); printf("n"); } return 0; }
  • 14. MULTI-DIMENSIONAL ARRAY C allows arrays of more-dimensions called multi- dimensional array. The general form of a multi-dimensional array is: Type array-name[s1][s2][s3]…..[sn] Where ‘s’ is the size of the dimension int survey[3][5][2]; float table[5][4][5][3];