diff options
Diffstat (limited to 'challenge-163/deadmarshal/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-163/deadmarshal/cpp/ch-2.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-163/deadmarshal/cpp/ch-2.cpp b/challenge-163/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..5b890d6477 --- /dev/null +++ b/challenge-163/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,19 @@ +#include<iostream> +#include<vector> + +int summations(std::vector<int> vec) +{ + for(std::size_t i{}; i < vec.size(); ++i) + for(std::size_t j{i+1}; j < vec.size(); ++j) + vec[j+1] = vec[j] + vec[j+1]; + return vec.back(); +} + +int main() +{ + std::vector<int> vec{1,2,3,4,5}; + std::vector<int> vec2{1,3,5,7,9}; + std::cout << summations(vec) << '\n'; + std::cout << summations(vec2) << '\n'; + return 0; +} |
