#include <stdio.h>//二分法查找

int Binary_search(int * a,int key);

int main(void)

{

   int ary[]={1,2,3,4,5,6,7,8,9};

   int t=Binary_search(ary,3);

   printf("the key of what we find in ary is:%d\n",t);

   return 0;

}

int Binary_search(int * a,int key)

{

   int low=0,n;

   for(n=0;*(a+n)!='\0';n++)

	   continue;

   int high=n-1;//获取数组的长度

   while(low<=high)

   {

       int mid=(low+high)/2;

       if(key<a[mid])

           high=mid-1;

       else if(key>a[mid])

           low=mid+1;

       else

           return mid;

   }

}