SlideShare a Scribd company logo
BY
OMKAR MAJUKAR
XI-A
ARRAY
 An array is collection of variable of
same datatype that are referenced
by a common name.
 Types of arrays-
1) SINGLE DIMENSIONAL ARRAYS.
2) TWO DIMENSIONAL ARRAYS.
SINGLE
DIMENSIONAL
ARRAYS The simplest form of an array is a
single dimentional array.
 The array is given a name and its
elements are referred to by their
subscripts or indices.
 C++ array’s index numbering
starts with 0.
BASE DATATYPE
 The data type of array elements is
known as the base type of the
array.
type array-name[size];
 The above statement declared
array marks has 50 elements,
marks[0] to marks[49].
 EXAMPLE-
#include<iostream.h>
void main()
{
const int size = 50;
float marks[size];
for(int i=0; i<size; i++)
{
cout<<“Enter marks of students”<<i+1<<“n”;
cin>>marks[i];
}
cout<<n”;
for(i=0; i<size; i++)
cout<<“marks[“<<i<<“]=“<<marks[i]<<“n”;
return 0;
}
 OUTPUT-
Enter marks of student1
89
Enter marks of student2
98
Enter marks of student3
88
Marks[0] = 89
Marks[1] = 98
Marks[2] = 88
MEMORY
REPRESENTATION OF
SINGLE DIMENSIONAL
ARRAYS Single dimension arrays are essentially lists of
same information of the same type and their
elements are stored in contiguous memory
location in their index order.
 For example, an array grade of type char with 8
declared as
char grade[8];
will have element grade[0] at 1st allocated
memory location, grade[1] at the next, and so
forth.
Since grade is a char type array, each
element size of 1 byte(a character size is 1 byte)
and it will be represented in the memory as shown
below-
GRADE
ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007
*An 8 element character array beginning at
location 2000 .
Total bytes = size of base datatype * no. of elements
Grade
[0]
Grade
[1]
Grade
[2]
Grade[
3]
Grade
[4]
Grade
[5]
Grade
[6]
Grade
[7]
ARRAY
TRAVERSAL Traversal- Accessing each element of array.
 Example-
#include<iostream.h>
Void main()
{
float PER[10];
int c;
for(c=0; c<10; c++)
{
cout<<“Enter percentage of student”<<c+1;
cin>>PER[c];
}
cout<<endl<<“Contents of array”<<endl;
for(c=0; c<10; ++c)
{
cout<<“Percentage of student”<<c+1<<“=“<<PER[c]<<endl;
}
}
SEARCHING FOR AN
ELEMENT IN A 1-D
ARRAY Sometimes we need to search an
element in an array.
 This can be only done by comparing the
search-item with each and every
element of the array.
 This process for searching for an
element in an array is called linear
search.
 EXAMPLE-
#include<iostream.h>
void main()
{
const int maxsize = 10;
int ARR[maxsize],srch,ndx,found=0;
cout<<endl<<“Enter array values”<<endl;
for(int c=0; c<maxsize; ++c)
cin>>ARR[c];
cout<<“Enter the value to be searched”;
cin>>srch;
for(c=0; c<maxsize; ++c)
{
if(ARR[c]==srch)
{
found=1;
ndx=c;
break;
}
}
if(found==1)
cout<<“First occurance is at index”<<ndx;
else
Cout<<“Value not found in the array”;
}
CHARACTER
ARRAY-STRINGS
 C++ stores sequence of characters I,e
string into character arrays.
 In character arrays arrays C++ puts a
special character after the last character
within the string to mark the end of string.
 The special character is known as null
character or 0.
For reading spaces within a string
gets() or getline() methods should be used
and for reading one word only cin can be
used.
 EXAMPLE-
#include<iostream.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
char st[50];
int c;
cout<<“Enter a string of characters”;
gets(st);
for(c=0; st[c]!=‘0’; c++)
{
if(c%2==0)
st[c]=toupper(st[c]);
else
st[c]=tolower(st[c]);
}
cout<<“Converted string = “<<st;
}
2 DIMENSIONAL
ARRAYS
 A 2-D array is an array in which each element is
itself an array.
 For instance, an array A[m][n] is an M by N table
with M rows and N columns containing M*N
elements.
No. of elements in 2-D array = No. of rows * No. of
columns
 The simplest form of a multi dimensioned array is 2-
D arrays, is an array having single dimensioned
array as its elements.
 The general form of the 2-D array declaration is
type array-name[rows][columns]
PROCESSING 2-D
ARRAYS
 To read or process a 2-D array, you
need to use nested loops.
 One loop processes the rows and other
the columns.
 If outer loop is for rows and inner loop
is for columns, then for each row index,
all columns are processed and then the
same process is repeated for next row
index.
 EXAMPLE-
#include<iostream.h>
void main()
{
float marks[4][3],sum,avg;
char grade[4];
int i,j;
for(i=0; i<4; i++)
{
sum = avg = 0;
cout<<“Enter 3 scores of student”<<i+1<<“:”;
for(j=0; j<3; j++)
{
cin>>marks[i][j];
sum+=marks[i][j];
}
avg = sum3;
if(avg<45.0)
grade[i] = ‘D’;
else if(avg<60.0)
grade[i] = ‘C’;
else if(avg<75.0)
grade[i] = ‘B’;
else
grade[i] = ‘A’;
}
for(i=0; i<4; i++)
{ cout<<“student”<<i+1<<“tTotal Marks = “;
cout<<marks[i][0] + marks[i][2]
cout<<“tGrade=“<<grade[i]<<“n”;
}
return 0;
}
 OUTPUT-
Enter 3 scores of student 1 : 78 65 46
Enter 3 scores of student 2 : 56 65 66
Enter 3 scores of student 3: 90 89 92
Enter 3 scores of student 4: 45 56 43
Student 1 Total Marks = 189 Grade = B
Student 2 Total Marks = 187 Grade = B
Student 3 Total Marks = 271 Grade = A
Student 4 Total Marks = 144 Grade = C
MEMORY
REPRESENTATION OF
2 DIMENSIONAL
ARRAYS Two dimensional arrays are stored in a row-
column matrix, where the first index
indicates the row and second indicates the
column.
 This means the second index changes
faster than the first index when accessing
the elements in the array in the order in
which they are actually stored in memory.
0 1 2 3 4 5
0
1
2
3
4
*A two dimensional array pay[5][7] in
memory.
 Total bytes=no. of rows*no. of
columns*size of base data type.
Pay[2][3]
Pay[3][1]
MATRICES AS 2-D
ARRAYS
 Matrix is a useful concept of
mathematics.
 A matrix is a set of mn numbers
arranged in the form of a rectangular
array of m rows and n columns.
 Such a matrix is called m*n(m by n)
matrix.
 Matrices can be represented through 2-
D arrays.
 EXAMPLE-
#include<iostream.h>
void main()
{
int A[3][3],B[3][3],r,c; //Read values in matrices
cout<<“Enter first matrix row wisen”;
for(r=0;r<3;r++)
{ for(c=0;c<3;c++)
{ cin>>B[r][c];
}
}
int flag=0; //loop to check equality
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{ if(A[r][c]!=B[r][c])
{ flag=1; break;
}
if(flag==1) break;
}
if(flag!=0)
cout<<“Matrices are unequaln”;
else
cout<<“Matrices are equaln”;
return 0;
}
 OUTPUT-
Enter first matrix row wise
1 2 3
4 5 6
7 8 9
Enter second matrix row wise
1 2 3
4 5 6
7 8 9
Matrices are equal
ARRAY
INITIALIZATION
 C++ provides the facility of array initialization at
the time of declaration.
 The arrays are initialized in the same way as other
variables are.
 The general form of array initialization is
Type array-name[size1]……[size N]={value-list};
 Following code initializes an integer array with 12
elements:
int days of month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
CALLING
FUNCTIONS WITH
ARRAYS When an arrays argument is passed to a
function, C++, in most contexts treats the
name of an array as if it were a pointer i,e.,
memory address of some element.
 That, if age is an int array to hold 10
integers then age stores the address of
age[0], the first element of an array i,e., the
array name age is a pointer to an integer
which is the first element of an array
age[10].
 EXAMPLE-
#include<iostream.h>
void main()
{
float large(float arr[],intn); //Function prototype
char ch;
int i;
float amount[50],big;
for(i=0;i<50;i++)
{
cout<<“nEnter element no”<<i+1<<“n”;
cin>>amount[i];
cout<<“nWant to enter more?(y/n)n”;
cin>>ch;
if(ch!=‘y’)
break;
}
if(i<50)
i++; //In case of incomplete loop
big=large(amount,i); //Call function large() by passing the array and its number of elements
cout<<“nThe largest element of the array is :”<<big<<“n”;
return 0;
}
float large(float arr[],int n)
{
if(arr[j]>max)
max=arr[j];
}
return(max);
}
 EXAMPLE-
Enter element no. 2
5
Want to enter more?(y/n)
y
Enter element no. 3
33
Want to enter more?(y/n)
y
Enter element no. 4
13
Want to enter more?(y/n)
n
The largest element of the array is :33
THANK
YOU

More Related Content

What's hot (16)

PPT
Arrays
fahadshakeel
 
PDF
Arrays in C
Kamruddin Nur
 
PDF
Multi dimensional array
Rajendran
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
DOCX
Array
Radha Rani
 
PDF
Model-Driven Software Development - Static Analysis & Error Checking
Eelco Visser
 
PPTX
Java arrays
Mohammed Sikander
 
PDF
Java cheatsheet
Anass SABANI
 
PPTX
Arrays in C language
Shubham Sharma
 
PPT
Qno 3 (a)
Praveen M Jigajinni
 
PPT
Qno 2 (c)
Praveen M Jigajinni
 
PPT
1 D Arrays in C++
poonam.rwalia
 
PPT
Java: Introduction to Arrays
Tareq Hasan
 
DOCX
Data Structure Project File
Deyvessh kumar
 
Arrays
fahadshakeel
 
Arrays in C
Kamruddin Nur
 
Multi dimensional array
Rajendran
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Array
Radha Rani
 
Model-Driven Software Development - Static Analysis & Error Checking
Eelco Visser
 
Java arrays
Mohammed Sikander
 
Java cheatsheet
Anass SABANI
 
Arrays in C language
Shubham Sharma
 
1 D Arrays in C++
poonam.rwalia
 
Java: Introduction to Arrays
Tareq Hasan
 
Data Structure Project File
Deyvessh kumar
 

Similar to Structured data type (20)

PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PPTX
Arrays & Strings.pptx
AnkurRajSingh2
 
PPTX
2- Dimensional Arrays
Education Front
 
PPT
Fp201 unit4
rohassanie
 
PPT
Unit 3 arrays and_string
kirthika jeyenth
 
PPTX
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
PPTX
3 (3)Arrays and Strings for 11,12,college.pptx
navaneethan2714
 
DOCX
Array assignment
Ahmad Kamal
 
PPT
2DArrays.ppt
Nooryaseen9
 
PDF
Arrays and library functions
Swarup Boro
 
PPTX
Arrays in C++
Kashif Nawab
 
PPTX
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
PPTX
Array BPK 2
Riki Afriansyah
 
PPT
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 
PPTX
COM1407: Arrays
Hemantha Kulathilake
 
PPTX
Array ppt you can learn in very few slides.
dwivedyp
 
PPTX
Array and its operation in C programming
Rhishav Poudyal
 
PPTX
C-Arrays & Strings (computer programming).pptx
yusuph2410
 
PPT
Topic20Arrays_Part2.ppt
adityavarte
 
PPTX
arrays.pptx
NehaJain919374
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
Arrays & Strings.pptx
AnkurRajSingh2
 
2- Dimensional Arrays
Education Front
 
Fp201 unit4
rohassanie
 
Unit 3 arrays and_string
kirthika jeyenth
 
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
3 (3)Arrays and Strings for 11,12,college.pptx
navaneethan2714
 
Array assignment
Ahmad Kamal
 
2DArrays.ppt
Nooryaseen9
 
Arrays and library functions
Swarup Boro
 
Arrays in C++
Kashif Nawab
 
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Array BPK 2
Riki Afriansyah
 
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 
COM1407: Arrays
Hemantha Kulathilake
 
Array ppt you can learn in very few slides.
dwivedyp
 
Array and its operation in C programming
Rhishav Poudyal
 
C-Arrays & Strings (computer programming).pptx
yusuph2410
 
Topic20Arrays_Part2.ppt
adityavarte
 
arrays.pptx
NehaJain919374
 
Ad

Recently uploaded (20)

PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Ad

Structured data type

  • 2. ARRAY  An array is collection of variable of same datatype that are referenced by a common name.  Types of arrays- 1) SINGLE DIMENSIONAL ARRAYS. 2) TWO DIMENSIONAL ARRAYS.
  • 3. SINGLE DIMENSIONAL ARRAYS The simplest form of an array is a single dimentional array.  The array is given a name and its elements are referred to by their subscripts or indices.  C++ array’s index numbering starts with 0.
  • 4. BASE DATATYPE  The data type of array elements is known as the base type of the array. type array-name[size];  The above statement declared array marks has 50 elements, marks[0] to marks[49].
  • 5.  EXAMPLE- #include<iostream.h> void main() { const int size = 50; float marks[size]; for(int i=0; i<size; i++) { cout<<“Enter marks of students”<<i+1<<“n”; cin>>marks[i]; } cout<<n”; for(i=0; i<size; i++) cout<<“marks[“<<i<<“]=“<<marks[i]<<“n”; return 0; }
  • 6.  OUTPUT- Enter marks of student1 89 Enter marks of student2 98 Enter marks of student3 88 Marks[0] = 89 Marks[1] = 98 Marks[2] = 88
  • 7. MEMORY REPRESENTATION OF SINGLE DIMENSIONAL ARRAYS Single dimension arrays are essentially lists of same information of the same type and their elements are stored in contiguous memory location in their index order.  For example, an array grade of type char with 8 declared as char grade[8]; will have element grade[0] at 1st allocated memory location, grade[1] at the next, and so forth.
  • 8. Since grade is a char type array, each element size of 1 byte(a character size is 1 byte) and it will be represented in the memory as shown below- GRADE ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007 *An 8 element character array beginning at location 2000 . Total bytes = size of base datatype * no. of elements Grade [0] Grade [1] Grade [2] Grade[ 3] Grade [4] Grade [5] Grade [6] Grade [7]
  • 9. ARRAY TRAVERSAL Traversal- Accessing each element of array.  Example- #include<iostream.h> Void main() { float PER[10]; int c; for(c=0; c<10; c++) { cout<<“Enter percentage of student”<<c+1; cin>>PER[c]; } cout<<endl<<“Contents of array”<<endl; for(c=0; c<10; ++c) { cout<<“Percentage of student”<<c+1<<“=“<<PER[c]<<endl; } }
  • 10. SEARCHING FOR AN ELEMENT IN A 1-D ARRAY Sometimes we need to search an element in an array.  This can be only done by comparing the search-item with each and every element of the array.  This process for searching for an element in an array is called linear search.
  • 11.  EXAMPLE- #include<iostream.h> void main() { const int maxsize = 10; int ARR[maxsize],srch,ndx,found=0; cout<<endl<<“Enter array values”<<endl; for(int c=0; c<maxsize; ++c) cin>>ARR[c]; cout<<“Enter the value to be searched”; cin>>srch; for(c=0; c<maxsize; ++c) { if(ARR[c]==srch) { found=1; ndx=c; break; } } if(found==1) cout<<“First occurance is at index”<<ndx; else Cout<<“Value not found in the array”; }
  • 12. CHARACTER ARRAY-STRINGS  C++ stores sequence of characters I,e string into character arrays.  In character arrays arrays C++ puts a special character after the last character within the string to mark the end of string.  The special character is known as null character or 0. For reading spaces within a string gets() or getline() methods should be used and for reading one word only cin can be used.
  • 13.  EXAMPLE- #include<iostream.h> #include<stdio.h> #include<ctype.h> void main() { char st[50]; int c; cout<<“Enter a string of characters”; gets(st); for(c=0; st[c]!=‘0’; c++) { if(c%2==0) st[c]=toupper(st[c]); else st[c]=tolower(st[c]); } cout<<“Converted string = “<<st; }
  • 14. 2 DIMENSIONAL ARRAYS  A 2-D array is an array in which each element is itself an array.  For instance, an array A[m][n] is an M by N table with M rows and N columns containing M*N elements. No. of elements in 2-D array = No. of rows * No. of columns  The simplest form of a multi dimensioned array is 2- D arrays, is an array having single dimensioned array as its elements.  The general form of the 2-D array declaration is type array-name[rows][columns]
  • 15. PROCESSING 2-D ARRAYS  To read or process a 2-D array, you need to use nested loops.  One loop processes the rows and other the columns.  If outer loop is for rows and inner loop is for columns, then for each row index, all columns are processed and then the same process is repeated for next row index.
  • 16.  EXAMPLE- #include<iostream.h> void main() { float marks[4][3],sum,avg; char grade[4]; int i,j; for(i=0; i<4; i++) { sum = avg = 0; cout<<“Enter 3 scores of student”<<i+1<<“:”; for(j=0; j<3; j++) { cin>>marks[i][j]; sum+=marks[i][j]; } avg = sum3; if(avg<45.0) grade[i] = ‘D’; else if(avg<60.0) grade[i] = ‘C’; else if(avg<75.0) grade[i] = ‘B’; else grade[i] = ‘A’; } for(i=0; i<4; i++) { cout<<“student”<<i+1<<“tTotal Marks = “; cout<<marks[i][0] + marks[i][2] cout<<“tGrade=“<<grade[i]<<“n”; } return 0; }
  • 17.  OUTPUT- Enter 3 scores of student 1 : 78 65 46 Enter 3 scores of student 2 : 56 65 66 Enter 3 scores of student 3: 90 89 92 Enter 3 scores of student 4: 45 56 43 Student 1 Total Marks = 189 Grade = B Student 2 Total Marks = 187 Grade = B Student 3 Total Marks = 271 Grade = A Student 4 Total Marks = 144 Grade = C
  • 18. MEMORY REPRESENTATION OF 2 DIMENSIONAL ARRAYS Two dimensional arrays are stored in a row- column matrix, where the first index indicates the row and second indicates the column.  This means the second index changes faster than the first index when accessing the elements in the array in the order in which they are actually stored in memory.
  • 19. 0 1 2 3 4 5 0 1 2 3 4 *A two dimensional array pay[5][7] in memory.  Total bytes=no. of rows*no. of columns*size of base data type. Pay[2][3] Pay[3][1]
  • 20. MATRICES AS 2-D ARRAYS  Matrix is a useful concept of mathematics.  A matrix is a set of mn numbers arranged in the form of a rectangular array of m rows and n columns.  Such a matrix is called m*n(m by n) matrix.  Matrices can be represented through 2- D arrays.
  • 21.  EXAMPLE- #include<iostream.h> void main() { int A[3][3],B[3][3],r,c; //Read values in matrices cout<<“Enter first matrix row wisen”; for(r=0;r<3;r++) { for(c=0;c<3;c++) { cin>>B[r][c]; } } int flag=0; //loop to check equality for(r=0;r<3;r++) { for(c=0;c<3;c++) { if(A[r][c]!=B[r][c]) { flag=1; break; } if(flag==1) break; } if(flag!=0) cout<<“Matrices are unequaln”; else cout<<“Matrices are equaln”; return 0; }
  • 22.  OUTPUT- Enter first matrix row wise 1 2 3 4 5 6 7 8 9 Enter second matrix row wise 1 2 3 4 5 6 7 8 9 Matrices are equal
  • 23. ARRAY INITIALIZATION  C++ provides the facility of array initialization at the time of declaration.  The arrays are initialized in the same way as other variables are.  The general form of array initialization is Type array-name[size1]……[size N]={value-list};  Following code initializes an integer array with 12 elements: int days of month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  • 24. CALLING FUNCTIONS WITH ARRAYS When an arrays argument is passed to a function, C++, in most contexts treats the name of an array as if it were a pointer i,e., memory address of some element.  That, if age is an int array to hold 10 integers then age stores the address of age[0], the first element of an array i,e., the array name age is a pointer to an integer which is the first element of an array age[10].
  • 25.  EXAMPLE- #include<iostream.h> void main() { float large(float arr[],intn); //Function prototype char ch; int i; float amount[50],big; for(i=0;i<50;i++) { cout<<“nEnter element no”<<i+1<<“n”; cin>>amount[i]; cout<<“nWant to enter more?(y/n)n”; cin>>ch; if(ch!=‘y’) break; } if(i<50) i++; //In case of incomplete loop big=large(amount,i); //Call function large() by passing the array and its number of elements cout<<“nThe largest element of the array is :”<<big<<“n”; return 0; } float large(float arr[],int n) { if(arr[j]>max) max=arr[j]; } return(max); }
  • 26.  EXAMPLE- Enter element no. 2 5 Want to enter more?(y/n) y Enter element no. 3 33 Want to enter more?(y/n) y Enter element no. 4 13 Want to enter more?(y/n) n The largest element of the array is :33