Description: This program implements the binary search algorithm.
/* This program implements the Binary
* Search Algorithm on an input sorted array*/
#include
#include
void main()
{
/*array a will hold the sorted numbers, n will hold the number to be searched*/
int a[10],n,mid,low=0,high=9;
clrscr();
/* Calculate middle location of the array*/
/* integer range may exceed and cause problem */
mid=(low+high)/2;
printf("\n Enter the array elements :");
for(low=0;low<10;low++)
scanf("%d",&a[i]);
low=0;
printf("\n Enter the no. to be searched :");
scanf("%d",&n);
while(low<=high)
{
if(a[mid]==n)
{
printf("\n The no. is found at the location : %d",mid+1);
break;
}
else if(a[mid]>n)
high=mid-1;
else if(a[mid]
printf("\n The no. is not found in the array");
getch();
}
Appreciation to my father who stated to me concerning this website, this web site is actually amazing.