#include<stdio.h>
#include<conio.h>
void main ()
{
int a[100] ,n ,i ,item ,beg ,end ,mid;
clrscr ();
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the numbers in ascending order :\n");
for (i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the no. to be searched : ");
scanf("%d",&item);
beg = 0;
end = n-1;
mid = (beg+end) /2;
while(beg<=end && item !=a[mid])
{
if (item>a[mid])
beg =mid + 1;
else
end = mid - 1 ;
mid = (beg+end) /2;
}
if (a[mid] == item)
printf(" %d is found in position %d",item,mid+1);
else
printf(" Item does not exist");
getch ();
}