Code doesnt search elements properly

#include
using namespace std;

void matrixsearch(int a[1000][1000],int m,int n,int x)
{
int i=0,j=n-1,flag=0;
while(i<m&&j>=0)
{
if(a[i][j]==x)
{
flag=1;
cout<<1;
break;
}
if(a[i][j]>x)
i++;
if(a[i][j]<x)
j–;

}
if(flag==0)
	cout<<0;

}

int main() {
int m,n,a[1000][1000],x,i,j;
cin>>m>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cin>>x;

matrixsearch(a,m,n,x);


return 0;

}

hi @muskanrathore01_4aab76aa7dafc189
Refer this -->

@muskanrathore01_4aab76aa7dafc189
I have corrected ur code also… It’s now working fine and passing all test cases…

What was the problem in the original code?? Can you explain?

in if(a[i][j] > x) it should be j-- and in other condition i++.

@muskanrathore01_4aab76aa7dafc189
I hope it’s clear now?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.