#include <stdio.h>
double fast_sqrt(double x) {
if (x <= 0) return 0;
double guess = x;
double epsilon = 1e-7; // 精度
while (fabs(guess * guess - x) > epsilon) {
guess = (guess + x / guess) / 2.0;
}
return guess;
}
int main() {
double number = 25.0;
double result = fast_sqrt(number);
printf("The square root of %.2f is approximately %.2f\n", number, result);
return 0;
} |