SlideShare a Scribd company logo
1 of 11
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

More Related Content

Similar to 19-Lec - Multidimensional Arrays.ppt

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

Data structure array
Data structure  arrayData structure  array
Data structure array
 
Array
ArrayArray
Array
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays
ArraysArrays
Arrays
 
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
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
2 arrays
2   arrays2   arrays
2 arrays
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 

More from AqeelAbbas94

lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjdlecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjdAqeelAbbas94
 
1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).ppt1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).pptAqeelAbbas94
 
2-Lec - History of OOP and Java (1) .ppt
2-Lec - History of OOP and Java  (1) .ppt2-Lec - History of OOP and Java  (1) .ppt
2-Lec - History of OOP and Java (1) .pptAqeelAbbas94
 
Lecture-32-33.pptx
Lecture-32-33.pptxLecture-32-33.pptx
Lecture-32-33.pptxAqeelAbbas94
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptxAqeelAbbas94
 
use_case+use_case description.pptx
use_case+use_case description.pptxuse_case+use_case description.pptx
use_case+use_case description.pptxAqeelAbbas94
 
555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.ppt555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.pptAqeelAbbas94
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptxAqeelAbbas94
 
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...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.pptxYour Title goes Here.pptx
Your Title goes Here.pptxAqeelAbbas94
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.pptAqeelAbbas94
 

More from AqeelAbbas94 (20)

lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjdlecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
lecture_5 (2).ppt hjhrrgjbgrmgrhbgrgghjd
 
1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).ppt1-Lec - Introduction vhvv,vbvv,v (2).ppt
1-Lec - Introduction vhvv,vbvv,v (2).ppt
 
2-Lec - History of OOP and Java (1) .ppt
2-Lec - History of OOP and Java  (1) .ppt2-Lec - History of OOP and Java  (1) .ppt
2-Lec - History of OOP and Java (1) .ppt
 
Lecture-32-33.pptx
Lecture-32-33.pptxLecture-32-33.pptx
Lecture-32-33.pptx
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
 
blue.pptx
blue.pptxblue.pptx
blue.pptx
 
use_case+use_case description.pptx
use_case+use_case description.pptxuse_case+use_case description.pptx
use_case+use_case description.pptx
 
555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.ppt555e81217b39f1c1262b33d0.ppt
555e81217b39f1c1262b33d0.ppt
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
 
hexagon.pptx
hexagon.pptxhexagon.pptx
hexagon.pptx
 
Lecture1.ppt
Lecture1.pptLecture1.ppt
Lecture1.ppt
 
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
wepik-exploring-the-robust-features-of-samsung-health-app-enhancing-well-bein...
 
lecture56.ppt
lecture56.pptlecture56.ppt
lecture56.ppt
 
04.ppt
04.ppt04.ppt
04.ppt
 
SelectionSort.ppt
SelectionSort.pptSelectionSort.ppt
SelectionSort.ppt
 
Lecture2 (1).ppt
Lecture2 (1).pptLecture2 (1).ppt
Lecture2 (1).ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
Your Title goes Here.pptx
Your Title goes Here.pptxYour Title goes Here.pptx
Your Title goes Here.pptx
 
SE_models_1.ppt
SE_models_1.pptSE_models_1.ppt
SE_models_1.ppt
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 

Recently uploaded

VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 

Recently uploaded (20)

VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 

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