Website Summary Files Commits Branches @commit @diff @stats
path: root / Week04 / Exercise21.cpp
diff options
context:
space:
mode:
1 files changed, 24 insertions, 0 deletions
-rw-r--r--Week04/Exercise21.cpp24
diff --git a/Week04/Exercise21.cpp b/Week04/Exercise21.cpp
new file mode 100644
index 0000000..d98a43d
--- /dev/null
+++ b/Week04/Exercise21.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+
+int main() {
+ unsigned int S, n;
+ std::cin >> S >> n;
+
+ double a = S, power_10 = 1;
+ while (a > 100.0) {
+ a /= 100.0;
+ power_10 *= 10.0;
+ }
+
+ double x_i = (10.0 - 190.0 / (a + 20.0)) * power_10;
+ double x_n = (x_i + S / x_i) / 2.0;
+ for (unsigned int i = 1; i < n; i++) {
+ double old_x = x_n;
+ x_n = (x_i + S / x_i) / 2.0;
+ x_i = x_n;
+ }
+
+ std::cout << x_i;
+
+ return 0;
+}