program of Binary search

#include
#include
main()
{
int n[10]={10,21,32,43,54,65,76,87,98,99};
int no,low,high,mid;
printf("Enter No to search");
scanf("%d",&no);
low=0;
high=9;
while(low<=high) { mid=(low+high)/2; if(non[mid])
low=mid+1;
else
{
printf("%d is found at %d th position",no,mid+1);
exit(0);
}
}
printf("No was not found");
return 0;
}

No comments:

Post a Comment