Jemar
0
Q:

create a 2d array c++

Two dimensional array:
int two_d[10][20];

Three dimensional array:
int three_d[10][20][30];
4

for (int i = 0; i < m; i++) 
{ 
   for (int j = 0; j < n; j++) 
   { 
      cout << arr[i][j] << " "; 
   } 
     
   // Newline for new row 
   cout << endl; 
}
0
data_type  array_name[size1][size2]....[sizeN];

data_type: Type of data to be stored in the array. 
           Here data_type is valid C/C++ data type
array_name: Name of the array
size1, size2,... ,sizeN: Sizes of the dimensions
0
#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;
}
0

New to Communities?

Join the community