diff options
1 files changed, 25 insertions, 0 deletions
| -rw-r--r-- | Week05/Exercise09.cpp | 25 |
diff --git a/Week05/Exercise09.cpp b/Week05/Exercise09.cpp new file mode 100644 index 0000000..adcd5b1 --- /dev/null +++ b/Week05/Exercise09.cpp @@ -0,0 +1,25 @@ +#include <iostream> + +int main() +{ + double z; + unsigned int n; + std::cin >> z >> n; + + double base = z - 1; + double sum = 0; + + for (unsigned int i = 1; i <= n; i++) { + double to_power = 1; + + for (unsigned j = 1; j <= i; j++) { + to_power *= base; + } + + sum += ((i + 1) % 2 ? -1.0 : 1.0) * to_power / i; + } + + std::cout << sum << std::endl; + + return 0; +} |
