1.

Write programto enter10 valuesintoand searchforelement entered bythe useusing binary search​

Answer»

e#includeVOID Bsearch(int a[],int);void main( ){clrscr( );int a[10],i,N;cout<<"enter 10 ELEMENT";for(i=0;i<10;i++){cin>>a[i];}cout<<"enter element to search";cin>>n;Bsearch(a[],n);getch();}void Bsearch(int a[],int item){int beg=0,end=9,mid,POS=0;while(beg<=end){mid=(beg+end)/2if(item==a[mid]) { POS=1; cout<<"item found , position="<a[mid]) { beg=mid+1; }else { end=mid-1; }}if(POS==0){cout<<"item not found";}}Happy coding !



Discussion

No Comment Found