Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Staircase_search.cpp #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}