binary search using recursion in c programming


Posted Date:     Total Responses: 0    Posted By: R V Vinod Babu   Member Level: Silver   Points/Cash: 2   


#include
#include
#define null 0
int a[10];
int binsrec(int x,int *,int *);
void main()
{
int n,res=0,i,l,h,j,k,p,q,temp;
clrscr();
l=0;
printf("Enter the number of elements:");
scanf("%d",&h);
n=h;
for(p=0;p{
printf("Enter the value:");
scanf("%d",&a[p]);
}
for(i=0;ifor(j=i;j{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
/*for(q=0;q{
printf("\n%d",a[q]);
} */
printf("Enter the element to find:");
scanf("%d",&k);
res=binsrec(k,&l,&h);
printf("%d",res);
if(res==0)
printf("Element not found");
else
printf("Element found");
getch();
}
int binsrec(int x,int *ll,int *hh)
{
int mid,re=0;
mid=(*ll+*hh)/2;
if(x==a[mid])
re=1;
else
{
if(x{
*hh=mid;
re=binsrec(x,ll,hh);
}
else
{
if(x>a[mid])
{
*ll=mid;
re=binsrec(x,ll,hh);
}
else
re=0;
}}
printf("%d",re);
return re;
}


Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: QUICK SORT using C programming
Previous Project: Simulation of Flow solving Navier Stokes Equation.

Return to Project Index

Post New Project


Related Projects


Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
Awards & Gifts
Active Members
TodayLast 7 Daysmore...

Online Members

Sreesh Kumar K
More...
 
ISC Technologies, Kochi - India. © All Rights Reserved.