Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int i,a[100],n,m,low,high,s;
- cin>>n;
- low=1,high=n;
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- }
- cout<<"search";
- cin>>s;
- while(low<=high)
- {
- m=(low+high)/2;
- if(s==a[m])
- {
- break;
- }
- else if(s<a[m])
- {
- high=m-1;}
- else if(s>a[m])
- {
- low=m+1;
- }}
- if(low>high)
- cout<<"not found";
- else
- cout<<"found";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement