how to store data in 2d array c++ code example
Example 1: 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;
}
Example 2: how to initialize 2d array with values c++
int main()
{
int arr[2][5] =
{
{1,8,12,20,25},
{5,9,13,24,26}
};
}