#include<iostream>
using namespace std;
int binary();
int n;
int a[100];
int main()
{
cout<<"enter the values";
for(int i=0; i<n; i++)
{
cin>>a[i];
}
int j;
cout<<"enter the value to be searched";
cin>>j;
binary(j,a[10],0,9);
return 0;
}
int binary(int j, int a[10], int x, int y)
{
int mid=(x+y)/2;
if(j==a[mid])
{
return mid;
}
else if(j>a[mid])
{
x=mid+1;
return binary(j,a[n],x,y);
}
else
{
y=mid-1;
return binary(j,a[n],x,y);
}
}
}
0 Comments