#include <stdio.h> int binary_find(int arry[], int find_value) { int low = 0; int high = sizeof(arry) / sizeof(arry[0]) - 1; while(low <= high) { int index = (low + high) / 2; if(arry[index] == find_value) { return index; } else if(arry[index] > find_value) { high = index -1; } else low = index + 1; } return -1; } int main(int argc, char* argv[]) { int arry[] = {2, 4, 5, 8, 12, 45, 56, 65}; int find_value = 2; int index = binary_find(arry, find_value); if(index < 0) printf("%d找不到", find_value); else printf("%d的位置为a:%d", find_value, index); }