Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, arr[100], bg, en, md, i, itm, loc=1;
- cout<<"Please Enter The Element Number: ";
- cin>>n;
- bg=1;
- en=n;
- md=int((bg+en)/2);
- cout<<"Please Enter Data One By One by Pressing Enter: ";
- for(i=1; i<=n; i++)
- cin>>arr[i];
- cout<<"Please Enter The ITEAM you want to search: ";
- cin>>itm;
- while (bg<=en && arr[md] != itm)
- {
- if(itm<arr[md])
- {
- en=md-1;
- }
- else
- {
- bg=md+1;
- }
- md=int((bg+en)/2);
- }
- if(arr[md]==itm)
- {
- loc=md;
- cout<<"Iteam Found in "<<loc<<" number location";
- }
- else
- {
- cout<<"Iteam Not Found";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement