Matrix search 2d array

Whats wrong with this code?

#include
using namespace std;

void stairCase(int a[][100], int n, int m, int key){
int i = 0; int j =n-1;

while(i<n && j>=0){
    if(a[i][j] < key){
        i++;
    }
    else if(a[i][j] > key){
        j--;
    }
    else if(a[i][j] == key){
        cout<<1;
        break;
    }

    
}

if(i == n || j<0)
    
    cout<<0;

}

int main(){
int n,m,a[100][100], key;

cin>>n>>m;
for(int i = 0; i<n; i++){
    for(int j = 0; j<m; j++){
        cin>>a[i][j];
    }
}
cin>>key;
stairCase(a,n,m,key);
return 0;

}

Hello @arjun.12narang this is the corrected code:


Happy Learning!!

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.