#include <iostream>
using namespace std;
int search(int a[4][4], int n, int x){
int i = 0;
int j = n - 1;
while( i < n && j >= 0){
if(a[i][j] == x){
cout<<"Found at "<<i<<" "<<j;
return 1;
} else if(a[i][j] > x){
j--;
} else {
i++;
}
}
}
int main()
{
int mat[4][4] = { {10, 20, 30, 40},
{15, 25, 35, 45},
{27, 29, 37, 48},
{32, 33, 39, 50}};
search(mat, 4, 31);
return 0;
}
using namespace std;
int search(int a[4][4], int n, int x){
int i = 0;
int j = n - 1;
while( i < n && j >= 0){
if(a[i][j] == x){
cout<<"Found at "<<i<<" "<<j;
return 1;
} else if(a[i][j] > x){
j--;
} else {
i++;
}
}
}
int main()
{
int mat[4][4] = { {10, 20, 30, 40},
{15, 25, 35, 45},
{27, 29, 37, 48},
{32, 33, 39, 50}};
search(mat, 4, 31);
return 0;
}