Challenge 6: Compute Sum of First 'n' Natural Numbers

In this challenge, your task is to compute the sum of the first 'n' natural numbers.

Problem Statement

Implement a sum_N_Numbers recursive function to compute the sum of the n natural numbers (where (n) is a function parameter). Start by thinking about the base case (the sum of the first 1 integers is?) and then think about the recursive case.

Note: Natural Numbers start from 1, i.e., 1, 2, 3, 4, 5, …

Input

A natural number n

Output

The sum of all numbers from 1 upto that input natural number n

Sample Input

7

Sample Output

28

Coding Exercise

Write your code in the code widget below. If you don’t get it right, don’t fret; the solution is also given.

Get hands-on with 1200+ tech skills courses.