diff options
feat(Week07): Add solutions
1 files changed, 29 insertions, 0 deletions
| -rw-r--r-- | Week07/Exercise09.cpp | 29 |
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 <iostream> + +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; +} |
