#include <stdlib.h>
int main()
{
int arr[8]={1,5,7,9,11,13,15,17};
int i,start=0,end=7,mid,key;
scanf("%d",&key);
do{
mid=(int)((start+end)/2);
if(arr[mid]==key){
printf("Find at the position of:%d\n",mid+1);
break;
}
else if(arr[mid]>key){
end=mid-1;
}
else{
start=mid+1;
}
}
while(start<=end);
if(start>end)
printf("%d is not found!!!\n",key);
return 0;
}
No comments:
Post a Comment