// Program for searching an element in the MATRIX
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ clrscr();
void search(int[50][50],int,int,int);
int A[50][50],i,j,m,n,k;
cout<<"Enter the size of matrix";
cin>>m>>n;
cout<<"\n Enter elements in matrix";
for(i=0;i<m;i++)
{ for(j=0;j<n;j++) //loop for reading matrix
cin>>A[i][j];
}
cout<<"\n Enter element to be searched";
cin>>k;
search(A,m,n,k); //reading the element
getch();
}
void search(int A[50][50],int m,int n,int k)
{ int i,j;
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ if(k==A[i][j])
{ cout<<"\n Element found";
getch();
exit(0);
}
}
}
cout<<"\n Element not found";
}
OUTPUT
Enter the size of matrix 2
2
Enter elements in matrix 1
2
3
4
Enter element to be searched
7
Element not found