From 3e8ac7ba4a8f410703aa5a8426f542217adcbf2f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 14 Nov 2025 20:55:42 +0200 Subject: feat(Week07): Add solutions --- Week07/Exercise09.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Week07/Exercise09.cpp (limited to 'Week07/Exercise09.cpp') diff --git a/Week07/Exercise09.cpp b/Week07/Exercise09.cpp new file mode 100644 index 0000000..d68b427 --- /dev/null +++ b/Week07/Exercise09.cpp @@ -0,0 +1,29 @@ +#include + +double topower(double x, unsigned int a) { + double result = 1.0; + for (unsigned int i = 1; i <= a; i++) + result *= x; + return result; +} + +int main() { + const unsigned int SIZE = 11; + double coeffs[SIZE], root; + + for (unsigned int i = 0; i < SIZE; i++) + std::cin >> coeffs[i]; + std::cin >> root; + + double sum = 0.0; + for (unsigned int i = 0; i < SIZE; i++) + sum += coeffs[i] * topower(root, 10 - i); + + const double ZERO_BORDER = 0.0001; + if (-ZERO_BORDER < sum && sum < ZERO_BORDER) + std::cout << "Is a root" << std::endl; + else + std::cout << "Not a root" << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d