View the step-by-step solution to:

You all know how to use loop to compute a sum of all values in the array. Here's an example: int arr[lO] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum =...

please help me with this c++ problem

-----------------------------------------------------------------------------------Screen Shot 2017-08-15 at 6.47.58 PM.png

Screen Shot 2017-08-15 at 6.47.58 PM.png

You all know how to use loop to compute a sum of all values in the array. Here's an example: int arr[lO] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = O; for (int i=0; i < 10; i++)
sum += arr[i]; The addition of all elements can be done using recursion. Remember, with recursion, at each step you need to make the problem smaller. In case
of the sum of the array elements, you can say that the sum of all elements is the sum of lst element and the rest of the array. Did you notice that
"sum of the rest of the array" is the same problem,just 1 element smaller? I want you to write and use recursive function to sum the elements of the array. The function can take 2 or 3 parameters, depending on how
comfortable you are with pointers. If you want the simpler solution, your function can take array, index of the starting element and the total size of the array.
If you know how to pass the address of the next element (instead of the array itself, which is address of the first element), then you do not need
to pass the index of the next element in the array (but the size should not be the size ofthe initial array but the remaining size). Handle the input in a separate function that prompts user to enter a specific number of elements (number of elements should be one of the
parameters to the input function). The size of the array can be whatever you want it to be.

Top Answer

#include <iostream> using namespace std ; int rec_func ( int *arr, int n) {    ... View the full answer

Sign up to view the full answer

Other Answers

Please see the attached... View the full answer

sum.cpp

#include<iostream>
using namespace std;
int call_sum(int arr, int N)
{
if (N <= 0)
return 0;
return (call_sum(arr,N - 1) + arr[N-1]);
}
int main()
{
int sum = 0,N;
cout<<"Enter...

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online