Python Program to Find the Sum of Natural Numbers

In this post, we will see how to find sum of natural numbers.

  • Initialize sum to 0
  • Iterate over range(n+1) and add to sum
  • You will get sum of all natural number in the end

Let’s see very simple python program for it.

n=11 sum=0 for i in range(n+1): sum+=i print("Sum is",sum)

Output:

Sum is 66

Can you find simpler solution?
Well, you can simply find sum of all natural numbers using below formula

n=11 sum=0 sum =(n*(n+1))/2 print("Sum is",sum)

Output:

Sum is 66

That’s all about finding sum of natural numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *