BINARY SEARCH THROUGH RECURSION in C language
binary search through recursion
binary search through recursion in c
binary search with recursion
Program:
#include
#include
void main()
{
int a[10],i,n,m,c,l,u;
clrscr();
printf("Enter the size regarding an array->");
scanf("%d",&n);
printf("\nEnter the elements regarding the array->");
for(i=0;i
{
scanf("%d",&a[i]);
}
printf("\nThe elements regarding an array are->");
for(i=0;i
{
printf(" %d",a[i]);
}
printf("\nEnter the number toward be search->");
scanf("%d",&m);
l=0,u=n-1;
c=binary(a,n,m,l,u);
if(c==0)
printf("\nThe number is not in the list");
else
printf("\nThe number is found");
getch();
}
int binary(int a[],int n,int m,int l,int u)
{
int mid,c=0;
if(l<=u)
{
mid=(l+u)/2;
if(m==a[mid])
{
c=1;
}
else
if(m
{
return binary(a,n,m,l,mid-1);
}
else
return binary(a,n,m,mid+1,u);
}
else
return c;
}