Created
June 3, 2020 09:01
-
-
Save bhaveshmunot1/01e1fbe19f0e6b411b2231e83d29a7df to your computer and use it in GitHub Desktop.
Find sum of numbers in an array using recursion.
This file contains 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
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