program for BINARY SEARCH in c language


 #include<stdio.h>

#include<conio.h>

void main()

{

int a[10],beg,end,item,i,loc,mid;

clrscr();

printf("\n Enter the array element");

for(i=0;i<=10;i++)

scanf("%d",&a[i]);

printf("\n Enter the no. to be search->");

scanf("%d",&item);

beg=0;end=9;

mid=(beg+end)/2;

while(beg<=end&&a[mid]!=item)

{

if(item<a[mid])

end=mid-1;

else

beg=mid+1;

mid=(beg+end)/2;

}

if(item==a[mid])

{

loc=mid;

printf("\n item located possition %d",loc+1);


}

else

{

loc=NULL;

printf("\n item not exist");

}

getch();

}