WAP for finding a location
#include<iostream.h>
#include<conio.h>
void main()
{
int a[4][4],n,m,i,j,loc=0,key;
cout<<"\n enter size of rows :";
cin>>n;
cout<<"\n enter size of collumns :";
cin>>m;
cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n 2d array \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
}
cout<<"\n\n Enter element which location is to be search :";
cin>>key;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]==key)
{
cout<<"\nelemt is present at "<< i << "row and "<<j<< "column";
break;
}
}
}
getch();
clrscr();
}
No comments:
Post a Comment