#include<stdio.h> #include<stdlib.h> void find(int arr1[], int key, int right) { int left = 0, mid; while (left <= right) { mid = (left + right) / 2; if (key == arr1[mid]) { printf("\n找到了,您要找的數是%d,位置為%d\n", key, mid+1); break; } else if (key > arr1[mid]) left = mid + 1; else right = mid - 1; } if (left = right) printf("\n您要找的數不存在,請重試!"); } int main() { int arr[] = {1, 3 ,4 ,5 ,6, 7, 9 ,13, 15 ,36 }; int k,len; len = sizeof(arr); printf("請輸入你要查找的數:"); scanf("%d", &k); find(arr,k,len); system("pause"); return 0; }