Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise11.cpp
diff options
context:
space:
mode:
Commit5ce214686e668bf185222b518b78d7f47a20b4fd (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-12-07 13:44:16 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-12-07 13:44:16 +0200
Filesacd2c1e0f3f0c7aa850878a12a9b674b8be1ccf7 /Week10/Exercise11.cpp
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.tar
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.tar.gz
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.zip
Parent6f894be622e8046f43a70e843cff7bd99c58a3c1 (diff)
feat(Week10): Add solutions
1 files changed, 32 insertions, 0 deletions
-rw-r--r--Week10/Exercise11.cpp32
diff --git a/Week10/Exercise11.cpp b/Week10/Exercise11.cpp
new file mode 100644
index 0000000..a906855
--- /dev/null
+++ b/Week10/Exercise11.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+
+int main() {
+ unsigned int n;
+ std::cin >> n;
+
+ double* coeffs = new double[n + 1];
+ for (unsigned int i = 0; i < n + 1; i++)
+ std::cin >> coeffs[i];
+
+ double potentialRoot;
+ std::cin >> potentialRoot;
+
+ double sum = 0.0, toPower = 1.0;
+ for (unsigned int i = n + 1; i > 0; i--) {
+ sum += coeffs[i-1] * toPower;
+ toPower *= potentialRoot;
+ }
+
+ const double ZERO_BORDER = 0.00001;
+
+ if (-ZERO_BORDER < sum && sum < ZERO_BORDER) {
+ std::cout << "Is a root" << std::endl;
+ }
+ else {
+ std::cout << "Not a root" << std::endl;
+ }
+
+ delete[] coeffs;
+
+ return 0;
+}