ArraySum Program
Description
The program uses a recursive method to calculate the total values of an integer array's elements.Associated Concepts:
Recursion
Algorithm:
main method:
addElements method definition:
Create an array with a number of integer elements.
Call the recursive method addElements() to calculate the total value of array elements, and pass the array and the size of the array as the arguments.
Call the recursive method addElements() to calculate the total value of array elements, and pass the array and the size of the array as the arguments.
addElements method definition:
If the array has only one element, return it.
Otherwise
Otherwise
Call addElements() method recursively to get the subtotal of
the array elements from 0 up to the second last element
Add the last element to the subtotal
Add the last element to the subtotal