#include<iostream>
using namespace std;
int main()
{
int a[15]={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};//这题是从大到小!!!!!!!
int l=0,h=14,x,m;
cout<<"输入查找的数:";
cin>>x;
while(l<=h)
{
m=(l+h)/2;
if(x==a[m])//==
{
break;
}
else if(x<a[m])//这里应该是<,下边那个是>
{
l=m+1;
}
else if(x>a[m])
{
h=m-1;
}
}
cout<<"是第"<<m+1<<"个数";
return 0;
}
这题是从大到小!!!!没注意题目 循环部分弄反了很久才发现