#include <stdio.h> #include <stdlib.h> #include<ctype.h> #include<string.h> #include<math.h> int main() { double x1 = 1.0, x2, a; scanf("%lf", &a); while (1) { x2 = (x1 + a / x1) / 2.0; if (x1 > x2) { if ((x1 - x2) < 0.00001) break; } else if ((x2 - x1) < 0.00001) break; x1 = x2; } printf("%.3lf", x1); return 0; } |
Double click to view unformatted code.