Whai is the error in this staircase search

#include
using namespace std;
void matrix( int ptr[][3])
{ int i,j,key=2;
for (i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>ptr[i][j];
}
}

   return;

}
void staircasesearch(int a[][3],int key)
{
int i,j;
i=0;
j=2;

   while(i<3&&j>=0)
   {
       if(a[i][j]==key)
       {
          cout<<"element found at "<<i<<"and"<<j<<endl;
          return; 
       }
       else if(a[i][j]>key)

       {
          j--;
       }
       else{
           i++;
       }
   }

}
int main() {
int arr[3][3];
matrix(arr);
staircasesearch(arr);

}

Hello @Bhavit_Singla,

I am executing your code for the problem: Matrix Search
Observations:

  1. You are not taking input for no. of rows and no. of columns
    (You have hard coded the size to 3X3)

  2. You are neither taking input for key nor passing any value of key to the function.
    (function call has one parameter and definition has two)

  3. The output format is wrong

  4. You are not considering the case when element is not present.

I have modified your code:

Hope, this would help.
Give a like, if you are satisfied.