Skip to content
Onsite

Sum of 1 to N

EasyP3Coding

Return 1 + 2 + ... + n using recursion. For n = 0 the sum is 0.

Example 1

Input
n = 5
Output
15
Why
1 + 2 + 3 + 4 + 5 = 15.

Example 2

Input
n = 0
Output
0

Example 3

Input
n = 1
Output
1

Constraints

  • 0 <= n <= 500

Hints

Run checks the 3 visible tests, Submit all 8.