Sum of Integers from 1 to n
In this lesson, we will learn how to find the sum of numbers from 1 to n using recursion.
What does the sum of integers from 1 to mean?
Natural numbers are all positive numbers starting with . These can be written as follows:
We want to write a program that takes a specific number and adds all the numbers from until that number.
For example, if , the sum of numbers from to is: .
Mathematical Notation
Let’s write it down mathematically:
.
.
.
Generic Mathematical Notation
.
.
.
$ … +2+1$
Implementation
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy