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]
Lecture 1 mte 407
Lecture 1 mte 407
 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
Lecture 1 mte 407
 #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

PDF
Matlab integration
PDF
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
PPT
16858 memory management2
DOCX
two dimensional array
DOC
Lab 9 sem ii_12_13
DOCX
Lab 10 sem ii_12_13
PDF
C- Programming Assignment 3
Matlab integration
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
16858 memory management2
two dimensional array
Lab 9 sem ii_12_13
Lab 10 sem ii_12_13
C- Programming Assignment 3

What's hot (19)

DOCX
Ankita sharma focp
PPTX
Pointers
PPT
Functions & Procedures [7]
PDF
C- Programming Assignment 4 solution
PDF
C++ ARRAY WITH EXAMPLES
PDF
C- Programming Assignment practice set 2 solutions
PPT
Dynamic allocation
PPT
PPT
16829 memory management2
DOC
Labsheet_3
PPTX
DATA TYPE IN PYTHON
DOC
Paper
PDF
C - Programming Assignment 1 and 2
PPTX
OPERATOR IN PYTHON-PART1
PPT
Thesis PPT
PDF
R programming lab 1 - jupyter notebook
PPTX
PPTX
Mathematics Function in C ,ppt
DOC
Ankita sharma focp
Pointers
Functions & Procedures [7]
C- Programming Assignment 4 solution
C++ ARRAY WITH EXAMPLES
C- Programming Assignment practice set 2 solutions
Dynamic allocation
16829 memory management2
Labsheet_3
DATA TYPE IN PYTHON
Paper
C - Programming Assignment 1 and 2
OPERATOR IN PYTHON-PART1
Thesis PPT
R programming lab 1 - jupyter notebook
Mathematics Function in C ,ppt
Ad

Similar to Lecture 1 mte 407 (20)

PPT
Java: Introduction to Arrays
PDF
Arrays-Computer programming
PPT
C Arrays.ppt
PDF
C sharp chap6
PDF
Unit 2
PPT
Arrays in c programing. practicals and .ppt
PPTX
Array
DOC
PDF
Arrays and library functions
PPTX
Array and its operation in C programming
PDF
Arrays and library functions
PDF
Arrays and strings in c++
PPT
Data Structure Midterm Lesson Arrays
PPTX
Chapter1.pptx
PDF
CP Handout#9
PDF
Homework Assignment – Array Technical DocumentWrite a technical .pdf
PPTX
Programming in C (part 2)
PPTX
Arrays in C language
PDF
ARRAYS
Java: Introduction to Arrays
Arrays-Computer programming
C Arrays.ppt
C sharp chap6
Unit 2
Arrays in c programing. practicals and .ppt
Array
Arrays and library functions
Array and its operation in C programming
Arrays and library functions
Arrays and strings in c++
Data Structure Midterm Lesson Arrays
Chapter1.pptx
CP Handout#9
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Programming in C (part 2)
Arrays in C language
ARRAYS
Ad

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Geodesy 1.pptx...............................................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Current and future trends in Computer Vision.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
Artificial Intelligence
PDF
737-MAX_SRG.pdf student reference guides
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Foundation to blockchain - A guide to Blockchain Tech
Automation-in-Manufacturing-Chapter-Introduction.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Geodesy 1.pptx...............................................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Current and future trends in Computer Vision.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mechanical Engineering MATERIALS Selection
Categorization of Factors Affecting Classification Algorithms Selection
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
III.4.1.2_The_Space_Environment.p pdffdf
Artificial Intelligence
737-MAX_SRG.pdf student reference guides
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf

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