数组中的数有一定的顺序:从小到大或从大到小
#include<stdio.h>
#define N 10
int sty(int K)
{
int a[N]={10,14,24,44,45,55,66,76,84,93};
int high,low,mid;
high=N-1;
low=0;
while(high>low)
{
mid=(high+low)/2;
if(K==a[mid])
return mid;
else if(K>a[mid])
low=mid+1;
else
high=mid-1;
}
return -1;
}
int main()
{
int K;
scanf("%d",&K);
if(sty(K)>=0)
printf("%d",sty(K));
if(sty(K)==-1)
printf("there is no key word that you want.");
return 0;
}