#include <stdio.h> int zheban(int x,int arr[],int left,int right) { while(left<=right) { int mid=left-(left-right)/2; if(x<arr[mid]) { right=mid-1; } else if(x>arr[mid]) { left=mid+1; } else { return arr[mid]; } } return -1; } int main () { int arr[8]={1,2,3,4,5,6,7,8}; int size=sizeof(arr)/sizeof(arr[0])-1; int ret=zheban(8,arr,0,size); if(ret==-1) { printf("not exist!"); } else { printf("%d\n",ret); } return 0; }