/*PROGRAM TO SEARCH AN ELEMENT IN THE MATRIX*/
#include<conio.h>
#include<iostream.h>
class search_matrix
{
int m,n,i,j,count,a[10][10],s;
public:
void input();
void output();
};
void search_matrix::input()
{
cout<<“Enter the order of the matrix: “;
cin>>m>>n;
cout<<“Enter “<<m*n<<” elements in the matrix:\n”;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
}
void search_matrix::output()
{
count=0;
cout<<“The given matrix is: \n”;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<a[i][j]<<” “;
cout<<endl;
}
cout<<“Enter the element to be searched: “;
cin>>s;
//SEARCHING THE ELEMENT*/
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(s==a[i][j])
{
cout<<“Given element is present at “<<i+1<<” row & “<<j+1<<” column\n”;
count++;
}
}
}
if(count==0)
cout<<“Element is not present in the matrix”;
else
cout<<“Element appears “<<count<<” time in the matrix”;
}
void main()
{
search_matrix s1;
clrscr();
s1.input();
s1.output();
getch();
}