Answer:
// here is code in C++.
#include <bits/stdc++.h>
using namespace std;
// main function
int main()
{
// variables
int r_size,c_size;
cout<<"enter the number of row:";
// read the value of row
cin>>r_size;
cout<<"enter the number of column:";
// read the value of column
cin>>c_size;
// create a 2-d array
int arr[r_size][c_size];
// read the value of array
cout<<"enter the elements of array:"<<endl;
for(int x=0;x<r_size;x++)
{
for(int y=0;y<c_size;y++)
{
cin>>arr[x][y];
}
}
cout<<"elements of the array are:"<<endl;
// print the array
for(int a=0;a<r_size;a++)
{
for(int b=0;b<c_size;b++)
{
cout<<arr[a][b]<<" ";
}
cout<<endl;
}
return 0;
}
Explanation:
Here we have demonstrate a 2- dimensional array. In which, how to read the elements and how to print elements of array.Read the value of row and column from user.Create a 2-d array of size r_sizexc_size. then read the elements of array either row wise or column wise. Then print the elements.To print the elements, we can go either row wise or column.
Output:
enter the number of row:2
enter the number of column:3
enter the elements of array:
1 2 3
2 3 4
elements of the array are:
1 2 3
2 3 4