1// Two dimensional array
2int a[2][3]= {
3 {1, 2, 3},
4 {4, 5, 6}
5 };
6
7 cout << a[1][1]; // Output is 5
8
9// Three dimensional array
10//[2] is elements; [3] is rows in elements; [4] is column in elemnents
11int a[2][3][2]= {
12 //Element 0
13 { {1, 2},
14 {2, 3},
15 {4, 5}
16
17 },
18
19
20 // Element 1
21 { {6, 7},
22 {8, 9},
23 {10, 11}
24
25 }
26 };
27
28 cout << a[0][1][1]; // Prints 3
29
1#include <iostream>
2using namespace std;
3int main(){
4 int n,m;
5 int a[n][m];
6 cin >> n >>m;
7 for ( int i=0; i<n; i++){
8 for (int j=0; j<m; j++){
9 cin >> a[i][j];
10 }
11 }
12
13 for ( int x=0; x<n; x++){
14 for (int y=0; y<m; y++){
15 cout << "a[" << x << "][" << y << "]: ";
16 cout << a[x][y] << endl;
17 }
18 }
19 return 0;
20}
1#include <array>
22 #include <iostream>
33
44 using namespace std;
55
66 //remember const!
77 const int ROWS = 2;
88 const int COLS = 3;
99
1010 void printMatrix(array<array<int, COLS>, ROWS> matrix){
1111 //for each row
1212 for (int row = 0; row < matrix.size(); ++row){
1313 //for each element in the current row
1414 for (int col = 0; col < matrix[row].size(); ++col){
1515 cout << matrix[row][col] << ' ';
1616 }
1717 cout << endl;
1818 }
1919 }
1 int MyArray[2][3] = { {2, 3, 4}, {12, 13, 14} };
2
3 //visualize
4 //2, 3, 4
5 //12, 13, 14
6
7 std::cout << MyArray[0][2] << endl; // 4
8 std::cout << MyArray[1][1] << endl; // 13
9
10//First square bracket means how many rows you want in your array
11//Second squire bracket is for how many qulam you want in your array