A program to initialize a 2-D array and display the location of each of it's element.

 

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],i,j;

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"Enter a number:";
cin>>a[i][j];
}
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"The number at "<<i+1<<" row and "<<j+1<<" coloumn is "<<a[i][j];
cout<<"\n";
}
}

getch();
}

 

< Back