#include<iostream>
using namespace std;
int main()
{
int a[] = {10,20,35,45,52,54,64,68,74,84}; //必须为有序数组
int b;
cout << "输入要查找的数字:";
cin >> b;
int fist=0, end=9,mid=(fist+end)/2 ;
while (a[mid] != b) //终止查找的条件
{
if (b > a[mid]) //目标数在右侧
{
fist = mid + 1; //重新确定首个元素
mid = (end + fist) / 2; //重新确定中值
}
else if (b < a[mid]) //目标数在左侧
{
end = mid - 1; //重新确定尾元素
mid = (fist + end) / 2; //重新确定中值
}
}
cout << "找到了,位置是:" << mid << endl; //输出目标元素位置
return 0;
}