View Code of Problem 74

#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    double x,a,y;
    cin>>a;
        x=a/2;
            y=1/2.0*(x+a/x);
    while(abs(x-y)>=0.00001){
        x=y;
        y=(x+a/x)/2;
    }
    cout<<fixed<<setprecision(3)<<y<<endl;
    return 0;
}

Double click to view unformatted code.


Back to problem 74