Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

tasreeb Group Title

binary search program in c++??

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Isaacisbeast123 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    do you need the whole process??

    • 2 years ago
  2. Isaacisbeast123 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Either use this short equation (arra[mid]!=num) //NOTE THE EXTRA flush AT END. //FYI endl = flush + "\n" (so that can also be used) cout<<"\nnot found" << flush ; else if (arra[mid]==num) cout<<"location is\t"<<mid; getch(); }

    • 2 years ago
  3. Isaacisbeast123 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Or if your looking for advanced use/// #include<iostream.h> #include<conio.h> #define siz 10 void main() { int arra[siz]={0}; int mid,beg=1,end=siz,loca=0,num; clrscr(); cout<<"Please Enter The Elements Of Array\n"; for(loca=0;loca<siz;loca++) { cin>>arra[loca]; } cout<<"Please enter the required number"; cin>>num; mid=(loca)/2; while(beg<end&&arra[mid]!=num) { if(num<arra[mid]) end=mid-1; else beg=mid+1; mid=(beg+end)/2; } if (arra[mid]!=num) cout<<"\nnot found"; else if (arra[mid]==num) cout<<"location is\t"<<mid; getch(); }

    • 2 years ago
  4. krithika Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Try this too if you want #include<iostream.h> #include<conio.h> void main() { int a[20],n,i,top,bottom,mid,f,s; clrscr(); cout<<"Enter the value of n:"; cin>>n; cout<<"\nEnter the values:\n"; for(i=0;i<n;i++) { cin>>a[i]; } cout<<"Enter the element to be searched:"; cin>>s; top=0; bottom=n-1; f=0; while(top<=bottom && f==0) { mid=(top+bottom)/2; if(s>a[mid]) { top=mid+1; } else if(s<a[mid]) { bottom=mid-1; } else f=1; } if(f==1) cout<<"Element found"; else cout<<"Element not found."; getch(); }

    • 2 years ago
  5. tasreeb Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.