Answers for "multidimensional array in c++"

C++
2

c++ code to write 2d array

#include <iostream>
using namespace std;
int main(){
	int n,m;
	int a[n][m];
	cin >> n >>m;
	for ( int i=0; i<n; i++){
		for (int j=0; j<m; j++){
			cin >> a[i][j];
		}
	}
	
	for ( int x=0; x<n; x++){
		for (int y=0; y<m; y++){
			cout << "a[" << x << "][" << y << "]: ";
			cout << a[x][y] << endl;
		}
	}
	return 0;
}
Posted by: Guest on August-11-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 "multidimensional array in c++"

Browse Popular Code Answers by Language