View Code of Problem 75

#include <stdio.h>
#include<math.h> 
double cal_sqrt(double a)
{
    double x=1;
    double y=1.0/2*(x+a/x);
    while(fabs(y-x)>1e-5)
    {
        x=y;
        y=1.0/2*(x+a/x);
    }
    return y;
}
  
int main()
{
    double a,b;
    scanf("%lf",&a);
    b=cal_sqrt(a);
    printf("%.3lf",b);
    return 0;
}

Double click to view unformatted code.


Back to problem 75