diff --git a/binarysearch.cpp b/binarysearch.cpp new file mode 100644 index 0000000..6980d1a --- /dev/null +++ b/binarysearch.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +#include +int binarysearch() +{ +int n,key; +cout<<"enter the size of the array"; +cin>>n; +int a[n]; +cout<<"enter the sorted array"; +for(int i=0;i>a[i]; +cout<<"enter the element to be searched"; +cin>>key; +int beg,end,mid; +beg=0; +end=n-1; +while(beg<=end) +{ +mid=(beg+end)/2; +if(key==a[mid]) +return a[mid]; +else if(key