forked from akshitagupta15june/100code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaircase_search.cpp
More file actions
51 lines (46 loc) · 802 Bytes
/
Copy pathstaircase_search.cpp
File metadata and controls
51 lines (46 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;
int search(int a[][1000],int n,int item)
{
int i,j;
int found=1;
for (i=0, j=n-1; i<n ,j>0; i++, j--)
{
if(item>a[i][j])
{
i++;
}
else if(item==a[i][j])
{
found=0;
break;
}
else
{
j--;
}
}
if(found==0)
{
cout<<"Item found at position";
}
else{
cout<<"Item not found";
}
}
int main()
{
int a[1000][1000];
int n,item;
cin>>n;
cin>>item;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
search(a,n,item);
return 0;
}