#include<bits/stdc++.h> using namespace std; typedef long long ll; int main (){ double a, x1, x2; scanf("%lf", &a); x1 = a; x2 = (x1+a/x1)/2; while(fabs(x2-x1)>1e-5){ x1 = x2; x2 = (x1+a/x1)/2; } printf("%.3lf\n", x2); return 0; } |
Double click to view unformatted code.