fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. using namespace std;
  4.  
  5. void accumulate_arr(vector<int>& arr, int idx = 0) {
  6. if (idx >= arr.size()) return;
  7. arr[idx] += ((idx == 0) ? 0 : arr[idx - 1]);
  8. accumulate_arr(arr, idx + 1);
  9. }
  10.  
  11. void solve() {
  12. vector<int> arr = {1,8,2,10,3};
  13. accumulate_arr(arr, 0);
  14. for (auto &i : arr) cout << i << " ";
  15. }
  16.  
  17. int main() {
  18. IOS;
  19. solve();
  20. return 0;
  21. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
1 9 11 21 24