#include <stdio.h> #include <math.h> int main(){ float x,x0,x1; scanf("%f",&x); x0=x/2; x1=(x0+x/x0)/2; do{ x0=x1; x1=(x0+x/x0)/2; }while(fabs(x0-x1)>=1e-8); printf("%.3f",x1); return 0; }
Double click to view unformatted code.