#include<stdio.h>
int BinarySearch(int S[],int x,int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(S[mid]==x ) return mid;
else if(S[mid]<x) low=mid+1;
else if(S[mid]>x) high=mid-1;
}
return -1;
}
void main()
{ int S[5]={1,2,3,4,5};
int Lenth,x;
printf("请输入查找的值:\n");
scanf("%d",&x);
Lenth=BinarySearch(S,x,5);
if(Lenth>-1)
printf("已经找到!元素下标为:%d\n",Lenth);
else printf("数组中不存在你输入的值!\n");
}