C语言:折半查找

#include<stdio.h>
#include<stdlib.h>
int main(){
int arr[] = { 1, 2, 3, 4, 5 };
int to_find = 2;
int i = 0;
for (; i < sizeof(arr) / sizeof(arr[0]); i++) {
if (to_find == arr[i]) {
break;
}
}
if (i == 5){
printf(“没找到!\n”);
}
else{
printf(“找到了!\n”);
}
system(“pause”);
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44779591/article/details/88896839
今日推荐