search in a matrix

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
#include <iostream>
#include <fstream>

using namespace 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;
}
Last edited on
Topic archived. No new replies allowed.