void find_number() { int array[15] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; int left = 0, right = 15-1; while (left <= right) { int mid = (left + right) / 2; if (array[mid] < 29) left = mid + 1; // 繼續搜尋剩下的右半段 else if (array[mid] > 29) right = mid - 1; // 繼續搜尋剩下的左半段 else if (array[mid] == 29) { // 找到了其中一個數字 cout << mid << ':' << array[mid]; return; } } cout << "找不到29"; }