View Code of Problem 74

#include<bits/stdc++.h>
using namespace std;
int main() {
	double x;
	cin >> x;
	double x1, x2;
	x1 = x;
	x2 = (x1 + x / x1) / 2;
	while (fabs(x1 - x2) > 0.00001) {
		x1 = x2;
		x2 = (x1 + x / x1) / 2;
	}
	printf("%.03f\n", x2);

	return 0;

}

Double click to view unformatted code.


Back to problem 74