#include<stdio.h>
int main()
{
int low = 0, high = 14, mid, x;
int static a[15] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 };
printf("put a number:");
scanf_s("%d", &x);
if ((x > a[high]) || (x < a[low]))
{
printf("无此数");
}
while (high >= low)//low到high之间表示的是查找范围
{
mid = (high + low) / 2;
if (x > a[mid])
{
low = mid + 1;
continue;
}
if (x < a[mid])
{
high = mid - 1;
continue;
}
if (x = a[mid])
{
printf("it locates in %d", mid + 1);
break;
}
}
if (low>high)
printf("无此数");
return 0;
}
11-04
298