diff options
feat(Week06): Add exercises and solutions
1 files changed, 28 insertions, 0 deletions
| -rw-r--r-- | Week06/Exercise18.cpp | 28 |
diff --git a/Week06/Exercise18.cpp b/Week06/Exercise18.cpp new file mode 100644 index 0000000..8c5cb64 --- /dev/null +++ b/Week06/Exercise18.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +int main() { + const unsigned int SIZE = 10; + float numbers[SIZE]; + + for (unsigned int i = 0; i < SIZE; i++) { + std::cin >> numbers[i]; + } + + double max_sum = numbers[0]; + for (unsigned int length = 1; length <= SIZE; length++) { + for (unsigned int start = 0; start <= SIZE - length; start++) { + double sum = 0.0; + + for (unsigned int i = start; i < length; i++) { + sum += numbers[i]; + } + + if (sum > max_sum) + max_sum = sum; + } + } + + std::cout << max_sum << std::endl; + + return 0; +} |
