Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

1. Basic Sum
Table of Contents

Problem Statement

Try it yourself

Problem Statement

Calculate the Sum of the First N Natural Numbers Using a Recursive Approach.

The sum of first N natural numbers is equal to N + (N-1) + (N-2) + ... + (3) + (2) + (1). The following table shows a sample input/output description table:

Input (s)Output (s)Explanation
N = 5Sum = 15The first 5 natural numbers are 1, 2, 3, 4, and 5. The sum of these numbers is 1 + 2 + 3 + 4 + 5 = 15.
N = 10Sum = 55The first 10 natural numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. The sum of these numbers is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.
N = 1Sum = 1The first natural number is 1. The sum of this number is 1.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Mark as Completed

Table of Contents

Problem Statement

Try it yourself