Computer Science, asked by shinyazeez123, 10 months ago

write a prog to enter 10 values into an array and search for an element entered by the user using binary searchराइट ए प्रोग्राम टो इंसर्ट वैल्यूज इन ज्वेलरी एंड सोच फौरन एलिमेंट एंड बाय थे यूजर यूजिंग बाइनरी सर्च ​

Answers

Answered by Anonymous
2

#include<iostream.h>

#include<conio.h>

void 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)/2

if(item==a[mid])

{

POS=1;

cout<<"item found , position="<<mid+1;

break;

}

else if(item>a[mid])

{

beg=mid+1;

}

else

{

end=mid-1;

}

}

if(POS==0)

{

cout<<"item not found";

}

}

Similar questions