SlideShare a Scribd company logo
Lecture 1
 An array is a group of same data type.
 For instance, An int array has the ements of
int types.
 A float array holds the elements of float
types.
 Let’s Consider a scenario where we need to find
out the average of 100 integer numbers entered
by user.
 In C, we have two ways to do this:
1) We can define 100 variables with int data type
and then perform 100 scanf() operations to
store the entered values in the variables and
then at last calculate the average of them.
2) We can have a single integer array to store all
the values, loop the array to store all the
entered values in array and later calculate the
average.
Surely, it is convenient to store same data types in
one single variable and later access them using
array index.
1. int num[35];
 [It means, An integer array of 35 elements]
2. char ch[10];
 [It means, an array of characters for 10
elements]
 It is possible to initialize an array during declaration. For
example,
 int mark[5] = {19, 10, 8, 17, 9};
 You can also initialize an array like this.
 int mark[] = {19, 10, 8, 17, 9};
 Here, we haven't specified the size. However, the compiler
knows its size is 5 as we are initializing it with 5 elements.
 Example 1: C Program to calculate the
average of N (N<10) using Array.
 Example 2: C Program to assign values to
one dimensional array.
 Example 3: C program to Display Largest
Element of an array
 Example 4: C program to check whether a
character is palindrome or not
 An array of arrays is known as 2D array. The
two dimensional (2D) array in C
programming is also known as matrix. A
matrix can be represented as a table of rows
and columns. Before we discuss more about
two Dimensional array lets have a look at the
following C program example.
Two dimensional (2D) arrays in C
programming with example
 #include <stdio.h>
 const int CITY = 2;
 const int WEEK = 7;
 int main()
 {
 int temperature[CITY][WEEK];
 // Using nested loop to store values in a 2d array
 for (int i = 0; i < CITY; ++i)
 {
 for (int j = 0; j < WEEK; ++j)
 {
 printf("City %d, Day %d: ", i + 1, j + 1);
 scanf("%d", &temperature[i][j]);
 }
 }
 printf("nDisplaying values: nn");
 // Using nested loop to display vlues of a 2d array
 for (int i = 0; i < CITY; ++i)
 {
 for (int j = 0; j < WEEK; ++j)
 {
 printf("City %d, Day %d = %dn", i + 1, j + 1, temperature[i][j]);
 }
 }
 return 0;
 For loop: for loop in C programming with example. A loop is used for
executing a block of statements repeatedly until a given condition
returns false.
 Structure:
 for (initialization; condition test; increment or decrement)
 {
 //Statements to be executed repeatedly
 }
 Nested loop: A nested loop is a loop within a loop. The most common
applications of loops are for matrix data (e.g., looping through the rows
and columns of a table). You can nest any type of loop inside any other
type; a for loop can be nested in a while loop.
 Structure:
 Outer-Loop
 {
 // body of outer-loop Inner-Loop
 {
 // body of inner-loop
 }
 }

More Related Content

What's hot

Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
AnkitaSharma463389
 
Pointers
PointersPointers
Pointers
NabishaAK
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
Animesh Chaturvedi
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
CGC Technical campus,Mohali
 
16829 memory management2
16829 memory management216829 memory management2
16829 memory management2
Sidharth Sundaresan
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
vikram mahendra
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
Animesh Chaturvedi
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
Ashwini Mathur
 
Py9 3
Py9 3Py9 3
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
AllNewTeach
 
6.array
6.array6.array

What's hot (19)

Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Pointers
PointersPointers
Pointers
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Lab 1
Lab 1Lab 1
Lab 1
 
16829 memory management2
16829 memory management216829 memory management2
16829 memory management2
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
Paper
PaperPaper
Paper
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
 
Py9 3
Py9 3Py9 3
Py9 3
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
6.array
6.array6.array
6.array
 

Similar to Lecture 1 mte 407

Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
C Arrays.ppt
C Arrays.pptC Arrays.ppt
C Arrays.ppt
ssuser0c1819
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
Array
ArrayArray
Array
Anil Dutt
 
Array
ArrayArray
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Kumar Boro
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
Maulen Bale
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
trupti1976
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
SURBHI SAROHA
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
ARRAYS
ARRAYSARRAYS
ARRAYS
muniryaseen
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Vivek Singh
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 

Similar to Lecture 1 mte 407 (20)

Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
C Arrays.ppt
C Arrays.pptC Arrays.ppt
C Arrays.ppt
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Unit 2
Unit 2Unit 2
Unit 2
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 

Recently uploaded (20)

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 

Lecture 1 mte 407

  • 2.  An array is a group of same data type.  For instance, An int array has the ements of int types.  A float array holds the elements of float types.
  • 3.  Let’s Consider a scenario where we need to find out the average of 100 integer numbers entered by user.  In C, we have two ways to do this: 1) We can define 100 variables with int data type and then perform 100 scanf() operations to store the entered values in the variables and then at last calculate the average of them. 2) We can have a single integer array to store all the values, loop the array to store all the entered values in array and later calculate the average. Surely, it is convenient to store same data types in one single variable and later access them using array index.
  • 4. 1. int num[35];  [It means, An integer array of 35 elements] 2. char ch[10];  [It means, an array of characters for 10 elements]
  • 5.
  • 6.
  • 7.  It is possible to initialize an array during declaration. For example,  int mark[5] = {19, 10, 8, 17, 9};  You can also initialize an array like this.  int mark[] = {19, 10, 8, 17, 9};  Here, we haven't specified the size. However, the compiler knows its size is 5 as we are initializing it with 5 elements.
  • 8.  Example 1: C Program to calculate the average of N (N<10) using Array.  Example 2: C Program to assign values to one dimensional array.  Example 3: C program to Display Largest Element of an array  Example 4: C program to check whether a character is palindrome or not
  • 9.  An array of arrays is known as 2D array. The two dimensional (2D) array in C programming is also known as matrix. A matrix can be represented as a table of rows and columns. Before we discuss more about two Dimensional array lets have a look at the following C program example. Two dimensional (2D) arrays in C programming with example
  • 10.
  • 11.  #include <stdio.h>  const int CITY = 2;  const int WEEK = 7;  int main()  {  int temperature[CITY][WEEK];  // Using nested loop to store values in a 2d array  for (int i = 0; i < CITY; ++i)  {  for (int j = 0; j < WEEK; ++j)  {  printf("City %d, Day %d: ", i + 1, j + 1);  scanf("%d", &temperature[i][j]);  }  }  printf("nDisplaying values: nn");  // Using nested loop to display vlues of a 2d array  for (int i = 0; i < CITY; ++i)  {  for (int j = 0; j < WEEK; ++j)  {  printf("City %d, Day %d = %dn", i + 1, j + 1, temperature[i][j]);  }  }  return 0;
  • 12.  For loop: for loop in C programming with example. A loop is used for executing a block of statements repeatedly until a given condition returns false.  Structure:  for (initialization; condition test; increment or decrement)  {  //Statements to be executed repeatedly  }  Nested loop: A nested loop is a loop within a loop. The most common applications of loops are for matrix data (e.g., looping through the rows and columns of a table). You can nest any type of loop inside any other type; a for loop can be nested in a while loop.  Structure:  Outer-Loop  {  // body of outer-loop Inner-Loop  {  // body of inner-loop  }  }