#include<stdio.h> #include<math.h> void main() { float a; scanf("%f", &a); float x1 = 1.0; float x2 = (x1 + a / x1) / 2.0; while (fabs(x2 - x1) >= 0.00001) { x1 = x2; x2 = (x1 + a / x1) / 2.0; } printf("%.3f", x2); } |
Double click to view unformatted code.