Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- int main()
- {
- int a[10],i,n,mid,beg,end,item;
- clrscr();
- cout<<"\nEnter the value of n:";
- cin>>n;
- cout<<"Enter elements";
- for(i=0;i<n;i++)
- cin>>a[i];
- cout<<"\nEnter the item to be searched:";
- cin>>item;
- beg=0;
- end=n-1;
- mid=(int)(beg+end)/2;
- while(beg<=end&&a[mid]!=item)
- {
- if(item<a[mid])
- end=mid-1;
- else
- beg=mid+1;
- mid=(int)(beg+end)/2;
- }
- if(a[mid]==item)
- cout<<"\nSearch is successful";
- else
- cout<<"\nSearch is unsuccessful";
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement