Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise22.cpp
blob: e27d97b2e201ec108fd3b854b2db8416ee8aa578 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>

double agm(double an, double gn, unsigned i) {
	if (i == 0)
		return (an + gn) / 2.0;
	else
		return agm((an + gn) / 2.0, sqrt(an * gn), i - 1);
}

int main()
{
	double a, b;
	unsigned n;
	std::cin >> a >> b >> n;

	std::cout << agm(a, b, n) << std::endl;

	return 0;
}