#include<stdio.h> int main() { printf("請輸入你要查找的(1~10之間)數\n"); int i; scanf_s("%d", &i); int arr[10] = {1,2,3,4,5,6,7,8,9,10}; int start=1, end=10, mid; while (start<=end) { mid = (start + end) / 2; if (arr[mid]>i) { end= mid-1; } else if (arr[mid] < i) { start = mid + 1; } else { printf(" 你要找的數是:%d\n", arr[mid]); break; } } return 0; }