#include<stdio.h> #include<math.h> int main() { int a; double x1,x2; scanf("%d",&a); x1=a; x2=1.0/2*(x1+a/x1); while(fabs(x2-x1)<0.00001) { x1=x2; x2=1.0/2*(x1+a/x1); } printf("%.3f",x2); return 0; }
Double click to view unformatted code.