Recursion
Recursion-12
Recursion-13
Recursion-14
~/algor $ cat problems/rekursiya-massiv-elementlari-yigindisi
Sum of array elements
Easy
1000 ms
64 MB
30%
You are given an array of $n$ integers. Using a recursive function, compute the sum of all its elements.
The recurrence:
$$\text{sum}(A, n) = \begin{cases} A[0], & n = 1 \\ A[n - 1] + \text{sum}(A, n - 1), & n > 1 \end{cases}$$
Input
The first line contains an integer $n$ ($1 \le n \le 100$). The second line contains $n$ integers $a_i$ separated by spaces ($-1000 \le a_i \le 1000$).
Output
The sum of the array elements.
Note
$1 \le n \le 100$, $-1000 \le a_i \le 1000$
Examples
Input #1
4 1 2 3 4
Output #1
10
Input #2
3 -5 10 -2
Output #2
3