//折半查找法
int arr[] = {100,90,80,70,60,50,40,30,20,10};//必须是按序排列的数组
int top,mid,bottom = 0;
int findNumber = 0;
printf("please input findNumber:\n");
scanf("%d",&findNumber);
top = sizeof(arr)/sizeof(arr[0]);
mid = (top + bottom) / 2;
while (bottom <= top)
{
if (findNumber == arr[mid])
{
printf("Found.%d\n",mid);
break;
}
else if (findNumber > arr[mid])
{
top = mid - 1;
}else
{
bottom = mid + 1;
}
mid = (top + bottom) / 2;
}
if (top < bottom)
{
printf("Not find.\n");
}