Sum of First N Numbers
Given an integer N, return the sum of first N natural numbers. Try to solve this using recursion.
Example 1:
Input : N = 4
Output : 10
Explanation : first four natural numbers are 1, 2, 3, 4.
Sum is 1 + 2 + 3 + 4 => 10.
Example 2:
Input : N = 2
Output : 3
Explanation : first two natural numbers are 1, 2.
Sum is 1 + 2 => 3.
Now Your Turn!
Pick the correct output for the given inputInput : N = 10
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= N <= 103