#include
int mid,i,arr[20],l=0,p,max,se;
int binsrch(int,int);
void main()
{
cout<<"ENTER SIZE OF THE ARRAY"<
cout<<"ENTER ELEMENTS IN ASCENDING ORDER"<
cout<<"enter element to be searched"<
p=binsrch(l,max);
if(p==1)
{
cout<<"search is succesful\n";
cout<<"element is found at:" <
else
cout<<"NOT SUCCESFUL\N";
getch();
}
int binsrch(int low,int high)
{
if(low==high)
{
if(arr[low]==se)
return 1;
else
return 0;
}
else
{
mid=(low+high)/2;
if(arr[mid]==se)
return 1;
else
{
if(se
else
binsrch(mid+1,high);
}
}
}
OUTPUT:
ENTER SIZE OF THE ARRAY
8
ENTER ELEMENTS IN ASCENDING ORDER
-2
0
7
8
23
45
56
78
enter element to be searched
56
search is succesful
element is found at:6
No comments:
Post a Comment