Sum of Integers from 1 to n
In this lesson, we'll learn how to find the sum of numbers from 1 to n.
What does the sum of integers from 1 to mean?
Natural numbers are positive numbers starting from . These can be written as:
We want to write a program that takes a number and sums up all the numbers from up to that number.
For example, if , then the sum of numbers from to is: .
Mathematical Notation
The sum of all numbers up to a number is equal to the sum of that number and the sum of all the numbers before it. 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