View Code of Problem 74

#include<iostream>
#include<math.h>
using namespace std;
 
int main(){
    double a,x1=1,x2;
    cin>>a;
    while(true){
        x2=(x1+a/x1)/2;
        if(fabs(x1-x2)<1e-5) break;
        x1=x2; 
    }
    printf("%.3lf",x2);
    return 0;
}

Double click to view unformatted code.


Back to problem 74