#include<stdio.h> #include<math.h> int main() { double a,x,t,p; scanf("%lf", &a); x = a/2; do { t = x; x = (x + a/x)/2; p = x; }while(fabs(t-p)>0.00001); printf("%.3lf", x); return 0; }
Double click to view unformatted code.