SlideShare a Scribd company logo
Arrays
Multidimensional Arrays
Practice Problems
 Write a C++ program to find the sum and average of one
dimensional integer array.
 Write a C++ program to swap first and last element of an
integer array.
 Write a C++ program to reverse the element of an integer
array.
 Write a C++ program to find the largest and smallest element
of an array.
Practice Problems
 Write a C++ program to find the largest and second largest
element of an array.
 Write a C++ program to find Even and Odd elements in an
array.
 Write a C++ program to determine whether elements of an
array are prime numbers.
 Item_Code is one-dimensional array of integers. Write a C++
function to efficiently search for a data Val from Item_Code.
If Val is present in the array then the function should return
value true/1 and false/0 otherwise.
Multidimensional Arrays
 Arrays can be multidimensional.
 A two dimensional array consists of Rows and
Columns as we have them in a matrix.
 To declare a two-dimensional array of size x, y:
data_type arrayName [ x ] [ y ];
 Where data_type can be any valid C++ data type
and arrayName will be a valid C++ identifier.
 x represents number of Rows and y represents
number of Columns
Multidimensional Arrays
 A two-dimensional array can be think as a table, which
will have x number of rows and y number of columns. A
2-dimensional array a of type float, which contains
three rows and four columns can be shown as below:
float a [ 3 ] [ 4 ];
Multidimensional Arrays
 Every element in array a is identified by an element
name of the form a[ i ][ j ], where a is the name of the
array, and i and j are the subscripts that uniquely identify
each element in a.
 Initializing Two-Dimensional Arrays
Multidimensional Arrays
 Multi-dimensioned arrays may be initialized by specifying
bracketed values for each row. Following are some examples
for declaration and initialization.
int val[3][4] = {
{0, 1, 2, 3} , //initializers for row indexed by 0
{4, 5, 6, 7} , //initializers for row indexed by 1
{8, 9, 10, 11} //initializers for row indexed by 2
};
int b[4][4] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int c[2][5] = {0}; //initialize all elements with 0
Example:
int main()
{
int rows=4, cols=2;
float array[rows][cols] = { {17.0, 25.5},
{23.95,41.25}, {37.25,60.5},{40.0,81.35}};
// output each array element's value
for ( int i = 0; i < rows; i++ )
for ( int j = 0; j < cols; j++ ) {
cout << "array[" << i << "][" << j << "]: ";
cout << array[i][j]<< endl;
}
}
Output:
Multidimensional Arrays
int main() {
const int ROW = 4;
const int COLUMN = 3;
int matrix[ROW][COLUMN];
for(int a = 0; a < ROW; a++)
{
for(int b = 0; b < COLUMN; b++)
{
cout << "Enter ROW " << a+1 << " COLUMN "<<b+1<<" ";
cin>>matrix[a][b];
}
}
for(int a = 0; a < ROW; a++) //display array contents
{
for(int b = 0; b < COLUMN; b++)
cout << matrix[a][b] << "t";
cout << endl;
}
}
Multidimensional Arrays
Output
Enter ROW 1 COLUMN 1 1
Enter ROW 1 COLUMN 2 2
Enter ROW 1 COLUMN 3 3
Enter ROW 2 COLUMN 1 4
Enter ROW 2 COLUMN 2 5
Enter ROW 2 COLUMN 3 6
Enter ROW 3 COLUMN 1 7
Enter ROW 3 COLUMN 2 8
Enter ROW 3 COLUMN 3 9
Enter ROW 4 COLUMN 1 10
Enter ROW 4 COLUMN 2 11
Enter ROW 4 COLUMN 3 12
1 2 3
4 5 6
7 8 9
10 11 12
Ad

Recommended

ARRAYS
ARRAYS
muniryaseen
 
Arrays and library functions
Arrays and library functions
Swarup Boro
 
Arrays
Arrays
Chukka Nikhil Chakravarthy
 
02 arrays
02 arrays
Rajan Gautam
 
Chapter 13.pptx
Chapter 13.pptx
AnisZahirahAzman
 
Arrays-Computer programming
Arrays-Computer programming
nmahi96
 
Arrays
Arrays
Notre Dame of Midsayap College
 
Introduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Data structure array
Data structure array
MajidHamidAli
 
Array
Array
hjasjhd
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
IIUM
 
Programming in c Arrays
Programming in c Arrays
janani thirupathi
 
Arrays
Arrays
VenkataRangaRaoKommi1
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
arrays.pptx
arrays.pptx
NehaJain919374
 
Arrays In C
Arrays In C
yndaravind
 
Java: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Arrays
Arrays
Steven Wallach
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Lecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
2 arrays
2 arrays
trixiacruz
 
Session 7 En
Session 7 En
guest91d2b3
 
Session 7 En
Session 7 En
SamQuiDaiBo
 
C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
CP Handout#7
CP Handout#7
trupti1976
 
Unit ii data structure-converted
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
trees_introduction.ppt ug yg i gg yg gj
trees_introduction.ppt ug yg i gg yg gj
AqeelAbbas94
 
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
AqeelAbbas94
 

More Related Content

Similar to 19-Lec - Multidimensional Arrays.ppt (20)

Data structure array
Data structure array
MajidHamidAli
 
Array
Array
hjasjhd
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
IIUM
 
Programming in c Arrays
Programming in c Arrays
janani thirupathi
 
Arrays
Arrays
VenkataRangaRaoKommi1
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
arrays.pptx
arrays.pptx
NehaJain919374
 
Arrays In C
Arrays In C
yndaravind
 
Java: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Arrays
Arrays
Steven Wallach
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Lecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
2 arrays
2 arrays
trixiacruz
 
Session 7 En
Session 7 En
guest91d2b3
 
Session 7 En
Session 7 En
SamQuiDaiBo
 
C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
CP Handout#7
CP Handout#7
trupti1976
 
Unit ii data structure-converted
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
Data structure array
Data structure array
MajidHamidAli
 
C Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
IIUM
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Java: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 

More from AqeelAbbas94 (20)

trees_introduction.ppt ug yg i gg yg gj
trees_introduction.ppt ug yg i gg yg gj
AqeelAbbas94
 
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
AqeelAbbas94
 
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
AqeelAbbas94
 
1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).ppt
AqeelAbbas94
 
2-Lec - History of OOP and Java (1) .ppt
2-Lec - History of OOP and Java (1) .ppt
AqeelAbbas94
 
Lecture-32-33.pptx
Lecture-32-33.pptx
AqeelAbbas94
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
AqeelAbbas94
 
use_case+use_case description.pptx
use_case+use_case description.pptx
AqeelAbbas94
 
555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.ppt
AqeelAbbas94
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
AqeelAbbas94
 
hexagon.pptx
hexagon.pptx
AqeelAbbas94
 
Lecture1.ppt
Lecture1.ppt
AqeelAbbas94
 
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
AqeelAbbas94
 
lecture56.ppt
lecture56.ppt
AqeelAbbas94
 
04.ppt
04.ppt
AqeelAbbas94
 
SelectionSort.ppt
SelectionSort.ppt
AqeelAbbas94
 
Lecture2 (1).ppt
Lecture2 (1).ppt
AqeelAbbas94
 
ch06.ppt
ch06.ppt
AqeelAbbas94
 
Your Title goes Here.pptx
Your Title goes Here.pptx
AqeelAbbas94
 
trees_introduction.ppt ug yg i gg yg gj
trees_introduction.ppt ug yg i gg yg gj
AqeelAbbas94
 
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
ch6_2_v1.ppt yh jkkj jhjh h jhyj hg hghh
AqeelAbbas94
 
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
AqeelAbbas94
 
1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).ppt
AqeelAbbas94
 
2-Lec - History of OOP and Java (1) .ppt
2-Lec - History of OOP and Java (1) .ppt
AqeelAbbas94
 
Lecture-32-33.pptx
Lecture-32-33.pptx
AqeelAbbas94
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
AqeelAbbas94
 
use_case+use_case description.pptx
use_case+use_case description.pptx
AqeelAbbas94
 
555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.ppt
AqeelAbbas94
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
AqeelAbbas94
 
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
AqeelAbbas94
 
Your Title goes Here.pptx
Your Title goes Here.pptx
AqeelAbbas94
 
Ad

Recently uploaded (20)

Pause Travail 22 Hostiou Girard 12 juin 2025.pdf
Pause Travail 22 Hostiou Girard 12 juin 2025.pdf
Institut de l'Elevage - Idele
 
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
taqyea
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
unit- 5 Biostatistics and Research Methodology.pdf
unit- 5 Biostatistics and Research Methodology.pdf
KRUTIKA CHANNE
 
Advanced_English_Pronunciation_in_Use.pdf
Advanced_English_Pronunciation_in_Use.pdf
leogoemmanguyenthao
 
REGRESSION DIAGNOSTIC II: HETEROSCEDASTICITY
REGRESSION DIAGNOSTIC II: HETEROSCEDASTICITY
Ameya Patekar
 
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays
 
apidays New York 2025 - Beyond Webhooks: The Future of Scalable API Event Del...
apidays New York 2025 - Beyond Webhooks: The Future of Scalable API Event Del...
apidays
 
SAP_S4HANA_EWM_Food_Processing_Industry.pptx
SAP_S4HANA_EWM_Food_Processing_Industry.pptx
vemulavenu484
 
最新版美国亚利桑那大学毕业证(UA毕业证书)原版定制
最新版美国亚利桑那大学毕业证(UA毕业证书)原版定制
Taqyea
 
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays
 
Untitled presentation xcvxcvxcvxcvx.pptx
Untitled presentation xcvxcvxcvxcvx.pptx
jonathan4241
 
apidays New York 2025 - Using GraphQL SDL files as executable API Contracts b...
apidays New York 2025 - Using GraphQL SDL files as executable API Contracts b...
apidays
 
Power BI API Connectors - Best Practices for Scalable Data Connections
Power BI API Connectors - Best Practices for Scalable Data Connections
Vidicorp Ltd
 
apidays New York 2025 - API Security and Observability at Scale in Kubernetes...
apidays New York 2025 - API Security and Observability at Scale in Kubernetes...
apidays
 
MEDIA_LITERACY_INDEX_OF_EDUCATORS_ENG.pdf
MEDIA_LITERACY_INDEX_OF_EDUCATORS_ENG.pdf
OlhaTatokhina1
 
Grote OSM datasets zonder kopzorgen bij Reijers
Grote OSM datasets zonder kopzorgen bij Reijers
jacoba18
 
Addressing-the-Air-Quality-Crisis-in-New-Delhi.pptx
Addressing-the-Air-Quality-Crisis-in-New-Delhi.pptx
manpreetkaur3469
 
最新版美国佐治亚大学毕业证(UGA毕业证书)原版定制
最新版美国佐治亚大学毕业证(UGA毕业证书)原版定制
Taqyea
 
KLIP2Data voor de herinrichting van R4 West en Oost
KLIP2Data voor de herinrichting van R4 West en Oost
jacoba18
 
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
taqyea
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
unit- 5 Biostatistics and Research Methodology.pdf
unit- 5 Biostatistics and Research Methodology.pdf
KRUTIKA CHANNE
 
Advanced_English_Pronunciation_in_Use.pdf
Advanced_English_Pronunciation_in_Use.pdf
leogoemmanguyenthao
 
REGRESSION DIAGNOSTIC II: HETEROSCEDASTICITY
REGRESSION DIAGNOSTIC II: HETEROSCEDASTICITY
Ameya Patekar
 
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays
 
apidays New York 2025 - Beyond Webhooks: The Future of Scalable API Event Del...
apidays New York 2025 - Beyond Webhooks: The Future of Scalable API Event Del...
apidays
 
SAP_S4HANA_EWM_Food_Processing_Industry.pptx
SAP_S4HANA_EWM_Food_Processing_Industry.pptx
vemulavenu484
 
最新版美国亚利桑那大学毕业证(UA毕业证书)原版定制
最新版美国亚利桑那大学毕业证(UA毕业证书)原版定制
Taqyea
 
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays
 
Untitled presentation xcvxcvxcvxcvx.pptx
Untitled presentation xcvxcvxcvxcvx.pptx
jonathan4241
 
apidays New York 2025 - Using GraphQL SDL files as executable API Contracts b...
apidays New York 2025 - Using GraphQL SDL files as executable API Contracts b...
apidays
 
Power BI API Connectors - Best Practices for Scalable Data Connections
Power BI API Connectors - Best Practices for Scalable Data Connections
Vidicorp Ltd
 
apidays New York 2025 - API Security and Observability at Scale in Kubernetes...
apidays New York 2025 - API Security and Observability at Scale in Kubernetes...
apidays
 
MEDIA_LITERACY_INDEX_OF_EDUCATORS_ENG.pdf
MEDIA_LITERACY_INDEX_OF_EDUCATORS_ENG.pdf
OlhaTatokhina1
 
Grote OSM datasets zonder kopzorgen bij Reijers
Grote OSM datasets zonder kopzorgen bij Reijers
jacoba18
 
Addressing-the-Air-Quality-Crisis-in-New-Delhi.pptx
Addressing-the-Air-Quality-Crisis-in-New-Delhi.pptx
manpreetkaur3469
 
最新版美国佐治亚大学毕业证(UGA毕业证书)原版定制
最新版美国佐治亚大学毕业证(UGA毕业证书)原版定制
Taqyea
 
KLIP2Data voor de herinrichting van R4 West en Oost
KLIP2Data voor de herinrichting van R4 West en Oost
jacoba18
 
Ad

19-Lec - Multidimensional Arrays.ppt

  • 2. Practice Problems  Write a C++ program to find the sum and average of one dimensional integer array.  Write a C++ program to swap first and last element of an integer array.  Write a C++ program to reverse the element of an integer array.  Write a C++ program to find the largest and smallest element of an array.
  • 3. Practice Problems  Write a C++ program to find the largest and second largest element of an array.  Write a C++ program to find Even and Odd elements in an array.  Write a C++ program to determine whether elements of an array are prime numbers.  Item_Code is one-dimensional array of integers. Write a C++ function to efficiently search for a data Val from Item_Code. If Val is present in the array then the function should return value true/1 and false/0 otherwise.
  • 4. Multidimensional Arrays  Arrays can be multidimensional.  A two dimensional array consists of Rows and Columns as we have them in a matrix.  To declare a two-dimensional array of size x, y: data_type arrayName [ x ] [ y ];  Where data_type can be any valid C++ data type and arrayName will be a valid C++ identifier.  x represents number of Rows and y represents number of Columns
  • 5. Multidimensional Arrays  A two-dimensional array can be think as a table, which will have x number of rows and y number of columns. A 2-dimensional array a of type float, which contains three rows and four columns can be shown as below: float a [ 3 ] [ 4 ];
  • 6. Multidimensional Arrays  Every element in array a is identified by an element name of the form a[ i ][ j ], where a is the name of the array, and i and j are the subscripts that uniquely identify each element in a.  Initializing Two-Dimensional Arrays
  • 7. Multidimensional Arrays  Multi-dimensioned arrays may be initialized by specifying bracketed values for each row. Following are some examples for declaration and initialization. int val[3][4] = { {0, 1, 2, 3} , //initializers for row indexed by 0 {4, 5, 6, 7} , //initializers for row indexed by 1 {8, 9, 10, 11} //initializers for row indexed by 2 }; int b[4][4] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int c[2][5] = {0}; //initialize all elements with 0
  • 8. Example: int main() { int rows=4, cols=2; float array[rows][cols] = { {17.0, 25.5}, {23.95,41.25}, {37.25,60.5},{40.0,81.35}}; // output each array element's value for ( int i = 0; i < rows; i++ ) for ( int j = 0; j < cols; j++ ) { cout << "array[" << i << "][" << j << "]: "; cout << array[i][j]<< endl; } }
  • 10. Multidimensional Arrays int main() { const int ROW = 4; const int COLUMN = 3; int matrix[ROW][COLUMN]; for(int a = 0; a < ROW; a++) { for(int b = 0; b < COLUMN; b++) { cout << "Enter ROW " << a+1 << " COLUMN "<<b+1<<" "; cin>>matrix[a][b]; } } for(int a = 0; a < ROW; a++) //display array contents { for(int b = 0; b < COLUMN; b++) cout << matrix[a][b] << "t"; cout << endl; } }
  • 11. Multidimensional Arrays Output Enter ROW 1 COLUMN 1 1 Enter ROW 1 COLUMN 2 2 Enter ROW 1 COLUMN 3 3 Enter ROW 2 COLUMN 1 4 Enter ROW 2 COLUMN 2 5 Enter ROW 2 COLUMN 3 6 Enter ROW 3 COLUMN 1 7 Enter ROW 3 COLUMN 2 8 Enter ROW 3 COLUMN 3 9 Enter ROW 4 COLUMN 1 10 Enter ROW 4 COLUMN 2 11 Enter ROW 4 COLUMN 3 12 1 2 3 4 5 6 7 8 9 10 11 12