Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find sum of numbers in an array using recursion.
int sum_of_array(vector<int> nums, int start_index, int end_index) {
if (start_index == end_index) {
return nums[start_index];
}
int sum = sum_of_array(nums, start_index+1, end_index);
return sum + nums[start_index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.