Question: Write a recursive method that will compute cumulative sums in an array. To find the cumulative sums, add to each value in the array the
Write a recursive method that will compute cumulative sums in an array. To find the cumulative sums, add to each value in the array the sum of the values that precede it in the array. For example, if the values in the array are [2, 3, 1, 5, 6, 2, 7], the result will be [2, (2) + 3, (2 + 3) + 1, (2 + 3 + 1) + 5, (2 + 3 + 1 + 5) + 6, (2 + 3 +1 + 5 + 6) + 2, (2 + 3 + 1 + 5 + 6 + 2) + 7] or [2, 5, 6, 11, 17, 19, 26]. The parenthesized sums in the previous example are the results of a recursive call.
Step by Step Solution
3.26 Rating (175 Votes )
There are 3 Steps involved in it
publicstaticvoidcumulativeSumint... View full answer
Get step-by-step solutions from verified subject matter experts
