aboutsummaryrefslogtreecommitdiff
path: root/challenge-163/deadmarshal/cpp/ch-2.cpp
blob: 5b890d647745b608ffefb9a48cb1665a64118d16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}