View Code of Problem 74

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
	double x1, x2;
	double a;
	cin >> a;
	x1 = 2.0;
	x2 = (x1 + a / x1) / 2;
	while (abs(x1 - x2) >= 0.00001) {
		x1 = x2;
		x2 = (x1 + a / x1) / 2.0;
	}
	cout <<fixed<<setprecision(3)<< x2;
}

Double click to view unformatted code.


Back to problem 74