#include <stdio.h>
#include <windows.h>
int main()
{
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 };
int ans = 9;
int left = 0;
int right = sizeof(arr) / sizeof(arr[0])-1;
while (left < right){
int mid = (left + right) / 2;
if (arr[mid]>ans){
right = mid-1;
}
if (arr[mid] < ans){
left = mid;
}
else{
printf("%d\n", mid);
break;
}
}
if (left>right){
printf("找不到\n");
}
system("pause");
return 0;
}
04-12
863
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-09
1012
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-12
531
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-17
3306
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-09
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)