(E) Sum of vector elements¶
Goal:
I will practice implementing recursion further as well as STL’s vector
.
Instructions:
Retrieve the code template: templates/06/sum/
-> student/06/sum/
.
For automated testing, the template contains the definition RECURSIVE_FUNC
.
You need not care about it, and you must not change it.
In the code template, implement function sum_recursive
that follows a recursive algorithm and returns the sum of
integers found in vector
.
The function should have only a single parameter: vector, the elements
of which will be added together.
Since the aim is to write a recursive function, loops (for
or while
)
are not allowed.
Example on program execution:
Enter integers separated by spaces: 1 2 3 4 5
Sum: 15
Tips for completing the assignment:
- In the same way as in the previous assignment, consider first what is a trivial case and how to divide the problem into a smaller instance of the same problem (or alternatively, you can consider these things in opposite order).
A+ presents the exercise submission form here.