Answers for "multi dimensional array c++"

C++
0

get elements of 2d array c++

#include <array>
2 #include <iostream>
3
4 using namespace std;
5
6 //remember const!
7 const int ROWS = 2;
8 const int COLS = 3;
9
10 void printMatrix(array<array<int, COLS>, ROWS> matrix){
11 //for each row
12 for (int row = 0; row < matrix.size(); ++row){
13 //for each element in the current row
14 for (int col = 0; col < matrix[row].size(); ++col){
15 cout << matrix[row][col] << ' ';
16 }
17 cout << endl;
18 }
19 }
Posted by: Guest on May-25-2020
-6

multidimensional array c++

int MyArray[2][3] = { {2, 3, 4}, {12, 13, 14} };

	//visualize
	//2, 3, 4
	//12, 13, 14

	std::cout << MyArray[0][2] << endl; // 4
	std::cout << MyArray[1][1] << endl; // 13

//First square bracket means how many rows you want in your array
//Second squire bracket is for how many qulam you want in your array
Posted by: Guest on April-24-2021
0

get elements of 2d array c++

void printMatrix(array<array<int, COLS>, ROWS> matrix){
for (auto row : matrix){
//auto infers that row is of type array<int, COLS>
for (auto element : row){
cout << element << ' ';
}
cout << endl;
}
Posted by: Guest on May-25-2020

Code answers related to "multi dimensional array c++"

Browse Popular Code Answers by Language