#include <stdio.h>
int sqrt_binary_search(int N) {
int low = 0, high = N, mid;
while (low <= high) {
mid = low + (high - low) / 2;
if (mid * mid == N) return mid;
if (mid * mid < N) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return high; // 返回小于等于平方根的最大整数
}
int main() {
int number = 25;
int result = sqrt_binary_search(number);
printf("The integer square root of %d is %d\n", number, result);
return 0;
} |