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