Sum of first N numbers

Beginner Problems Basic Recursion Easy

Given an integer N, return the sum of first N natural numbers. Try to solve this using recursion.

Examples:

Input : N = 4

Output : 10

Explanation : first four natural numbers are 1, 2, 3, 4.

Sum is 1 + 2 + 3 + 4 => 10.

Input : N = 2

Output : 3

Explanation : first two natural numbers are 1, 2.

Sum is 1 + 2 => 3.

Input : N = 10

Constraints

  • 1 <= N <= 103

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree