Binary search program using c

#include<stdio.h>
#include<conio.h>
Void main()
{
int   i,first,last, middle,search,a[20],n;
Printf("\n enter the limit");
Scanf("%d",&n);
Printf("\n enter the %d integers",n);
for(i=0;i<=n;i++)
scanf("%d",&a[i]);
printf("\n entered number to be searched");
scanf("%d",& searched);
first=0;
last=n-1;
middle=(first+last)/2;
while(first<=last)
{
if(a[middle]<search)
first=middle+1;
else if (a[middle]==search)
{
printf("\n %d is persent in the position%d",search, middle+1);
}
else
last=middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("the number %d is not found \n", search);
getch();
}

Output:
             Enter the limit 5

             Enter the 5 integers
             10
             25
             32
             45
             52
             Enter the number to be searched 45
             45 is persent in the position 4



Comments