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,mid;
- cin>>n;
- cout<<"search: ";
- cin>>m;
- low=0,high=n-1;
- cout<<"enter the array: ";
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- }
- while(low<=high)
- {
- cout<<"search: ";
- cin>>m;
- mid=(low+high)/2;
- if(m==a[mid])
- {
- break;
- }
- else if(m<a[m])
- {
- high=mid-1;}
- else if(m>a[m])
- {
- low=mid+1;
- }
- if(low>high)
- cout<<"not found";
- else
- cout<<"found";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement