SlideShare a Scribd company logo
1 of 12
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 (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 Arrays and Loops in C

Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programmingnmahi96
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Kumar Boro
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysMaulen Bale
 
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 .pdfaroraopticals15
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
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 Unit2YOGESH SINGH
 

Similar to Arrays and Loops in C (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

Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxsomshekarkn64
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 

Arrays and Loops in C

  • 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  }  }