Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhaveshmunot1/01e1fbe19f0e6b411b2231e83d29a7df to your computer and use it in GitHub Desktop.
Save bhaveshmunot1/01e1fbe19f0e6b411b2231e83d29a7df to your computer and use it in GitHub Desktop.
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