View Code of Problem 74

#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
double EPS=0.00001;
int main(){
    double a,x,y;
    cin>>a;
    x=a/2;
    y=(x+a/x)/2;
    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