Question: Write a function arraySum that accepts two arguments: an array of integers and a number indicating the number of elements. The function will recursively calculate

Write a function arraySum that accepts two arguments: an array of integers and a number indicating the number of elements. The function will recursively calculate the sum of all the numbers in the array. The program will initialize the array, display the elements, and then display the result of the function call.

The solution must use recursion.

Sample Main:

int main()

{

int sum = 0; // Create an array with some values in it.

int myArray[] = { 1, 2, 3, 4, 5, 6, 7};

for(int i = 0; i

cout

// Display the sum of the values by calling the recursive function.

sum =

cout

// could also use, although difficult to debug: //

cout

}

Write a function arraySum that accepts two arguments: an array of integers

1 2 3 4 5 6 7 The sum of the array elements is: 28 Process returned 0 (0x8) execution time : 0.062 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!