Respuesta :

Answer:

// here is code in C++ to demonstrate a 2-dimensional array.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

int r,c;

cout<<"enter the number of row:";

// read the value of row

cin>>r;

cout<<"enter the number of column:";

// read the value of column

cin>>c;

// create a 2-d array

int arr[r][c];

// read the value of array

cout<<"enter the elements of array:"<<endl;

for(int a=0;a<r;a++)

{

   for(int b=0;b<c;b++)

   {

       cin>>arr[a][b];

   }

}

cout<<"elements of the array are:"<<endl;

// print the array

for(int a=0;a<r;a++)

{

   for(int b=0;b<c;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 rxc. 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:3

enter the number of column:3

enter the elements of array:

1 2 3

9 8 7

2 4 6

elements of the array are:

1 2 3

9 8 7

2 4 6