Monday, May 11, 2009

C-PROGRAM FOR BINARY SEARCH USING RECURSIVE FUNCTION

#include
#include
int key;
void main()
{
int a[50],i,n,loc;
int bin();
printf("\nenter the size of the array");
scanf("%d",&n);
printf("%d\n",n);
printf("\narray elements?\n\n");
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
printf("%5d",a[i]);
printf("\n");
printf("\nelement to be searched");
scanf("%d",&key);
printf("\n%d",key);
loc=bin(a,0,n);
printf("\n\n");
if(loc==0)
printf("\nunsuccessful search %d not found\n",key);
else
{
printf("\nsuccessful search");
printf("\n%d found at position %d \n",key,loc);
}
getch();
}

No comments:

Post a Comment