/****************************
WAP TO SEARCH ELEMENT IN
ARRAY USING BINARY SEARCH.
****************************/
#include stdio.h
#include conio.h
void main()
{
int a[100],n,i,ele,low,high,mid,flag;
clrscr();
printf("Enter size of array: ");
scanf("%d",&n);
printf("Enter %d sorted elements: ",n);
for(i=0;iele)
{
high=mid-1;
}
else
{
low=mid+1;
}
}
}
if(flag==1)
{
printf("Element Found at %d position.",mid+1);
}
else
{
printf("Element not Found.");
}
getch();
}
No comments:
Post a Comment