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