diff --git a/binarysearch.cpp b/binarysearch.cpp new file mode 100644 index 00000000..fea23ebc --- /dev/null +++ b/binarysearch.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +int main() +{ + int i, arr[10], num, first, last, middle; + cout<<"Enter 10 Elements (in ascending order): "; + for(i=0; i<10; i++) + cin>>arr[i]; + cout<<"\nEnter Element to be Search: "; + cin>>num; + first = 0; + last = 9; + middle = (first+last)/2; + while(first <= last) + { + if(arr[middle]last) + cout<<"\nThe number, "<