#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,key;
int a[1000][1000];
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cin>>key;
i=0;
j=n-1;
if(key==a[0][0])
{
cout<<“found at index 0,0”<<endl;
}
else if(key==a[n-1][n-1])
{
cout<<“found at index “<<n-1<<”,”<<n-1<<endl;
}
while(i<=j)
{
if(key>a[i][j])
{
i++;
}
else if(key<a[i][j])
{
j–;
}
else
{
cout<<“found at index “<<i<<”,”<<j;
break;
}
}
}
this code is not showing answer for some of the elements,plese check it and correct it
Problem in staircase search code
please share code in cb ide
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.