#include "stdio.h"
int main()
{
int x = 1;
int a[10];
int s = 0, i = 0, mid = 0, b = 0;
start:
printf("请输入一个有序数组10个数(从小到大):");
s = sizeof(a)/sizeof(a[0]);
for(i=0; i<s; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<s-1; i++)
{
if(a[i]>a[i+1])
{
printf("不是一个有序的数组,请重新输入:");
goto start;
}
}
printf("请输入想要查找的数:");
scanf("%d",&b);
int left = 0, right = i-1;
mid = (left+right)/2;
if(a[mid]>b)
{
right = mid;
}
if(a[mid]<b)
{
left = mid;
}
if(a[mid] == b)
{
printf("找到了:%d\n",a[mid-1]);
}
else
{
printf("找不到:-1\n.");
}
return 0;
}