Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Staircase_search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
using namespace std;
int staircaseSearch(int arr[][100], int n, int key)
{
int i = 0;
int j = n - 1;
while (i <= n && j >= 0)
{
if (arr[i][j] == key)
{
cout << "Number found at (" << i+1 << "," << j+1 << ")\n";
return 1;
}
else if (arr[i][j] < key)
{
i++;
}
else
{
j--;
}
}
cout << "Number not found\n";
}
int main()
{
int n;
cin >> n;
int arr[100][100] = {0};
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> arr[i][j];
}
}
int key;
cin >> key;
staircaseSearch(arr, n, key);
return 0;
}