View Code of Problem 74

#include <stdio.h>
#define  ABS(x) x > 0 ? x: -x

int main(void)
{
    double x, a;
    while(scanf("%lf",&x)!= EOF)
    {
        a = x;
        while(1)
        {
            x = (x + a / x) /2;
            if(x - (x + a / x) / 2 < 0.00001)
            {

                printf("%.3lf\n",x);
                break;
            }
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 74