Elements of Two-Dimensional Array in C

Write a c program to print the elements of the two-dimensional array in matrix form. An array of arrays can be defined as a two-dimensional array. The matrices that make up the 2D array are represented as a collection of rows and columns. 2D arrays, on the other hand, are used to build a data structure that resembles that of a relational database.

#include<iostream>
using namespace std;
int main()
{
int arr[10][10], rows, cols, i, j;
cout<<"\n Enter the rows elements for array";
cin>>rows;
cout<<"\n Enter the column elements for array";
cin>>cols;
cout<<"\n Enter "<<rows<<"*"<<cols<<"Array elements are\n";
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<" ";
cin>>arr[i][j];
}
}
cout<<"\n 2D array is\n";
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<" "<<arr[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}

 

Output:

Enter the rows elements for array2

Enter the column elements for array2

Enter 2*2Array elements are
34
45
67
89

2D array is
34 45
67 89