Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise22.cpp
diff options
context:
space:
mode:
1 files changed, 20 insertions, 0 deletions
-rw-r--r--Week13/Exercise22.cpp20
diff --git a/Week13/Exercise22.cpp b/Week13/Exercise22.cpp
new file mode 100644
index 0000000..e27d97b
--- /dev/null
+++ b/Week13/Exercise22.cpp
@@ -0,0 +1,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;
+}