Created
March 11, 2021 21:16
-
-
Save chrisdel101/97def73a9ef1ff553a52138e53acdeb1 to your computer and use it in GitHub Desktop.
adder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int add(vector<int> myElements, int sum) | |
{ | |
if (myElements.size() == 0) | |
{ | |
cout << "sum " << sum << endl; | |
return sum; | |
} | |
sum += myElements.back(); | |
myElements.pop_back(); | |
add(myElements, sum); | |
} | |
int main() | |
{ | |
vector<int> nums1 = {1, 2, 3, 4}; | |
vector<int> nums2 = {100, 200, 300, 400}; | |
vector<int> nums3 = {1000, 2000, 3000, 4000}; | |
add(nums1, 0); | |
add(nums2, 0); | |
add(nums3, 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment