hello guys am trying to search a specific value in my matrix if its der than output value is in matrix if not output value is not in matrix...........but my code is not working plzzzzzzzzzzzzzzz help me
#include <iostream>
#include <fstream>
usingnamespace std;
int searchmatrix(int x,int y)
{
ifstream infile("input.txt");
int arr[20][20];
infile>>x;
infile>>y;
int i,j;
//////////////////////////////////////////infiling to text file
for(i=0;i<x;i++)
{
for(j=0;j<x;j++)
{
infile>>arr[i][j];
}
}
////////////////////////////////////////////search mtrix
for(i=0;i<x;i++)
{
for(j=0;j<x;j++)
{
if(arr[i][j]!=y) return 1 ;
}
}
}
int main()
{
int x=0;
int y=0;
int flag;
flag=searchmatrix(x,y);
if(flag)
{
cout<<"value is in matrix"<<endl;
}
else
cout<<"value is not in matrix"<<endl;
return 0;
voidsearch(constMatrix& m, intx, int& i, int& j) {
// Pre: m is a non-empty matrix
// Post: i and j define the location of a cell that
// contains the value x in M. In case x is not in m,
// then i = j = -1
intnrows = m.size();
intncols = m[0].size();
for(i = 0; i < nrows; ++i) {
for(j = 0; j < ncols; ++j) {
if(m[i][j] == x) return;
}
}
i = -1;
j = -1;
}