Python Program to Find the sum of First N natural                                                       Number

In this article, we will see Python Program to Find the Sum of First N Natural Numbers. A Natural number is the same as a Counting number. They are used to Count the number of real physical objects. Natural numbers start from 1 and go on infinite.

The positive numbers 1,2,3 ... are known as natural numbers.

The formula for Sum of First n natural numbers is n(n+1)/2.

If you want to add the first 5 Natural numbers then we find the Sum of 1+2+3+4+5 =15.

Flow Diagram:-

sum1.jpg

Code:-

  • Start.

  • Declare and initialize variable, i,num, s=0.

  • Enter the value of num i.e. number up to which sum is to be calculated.

  • Use Loop to add numbers. Any of while, do-while or for loop can be used.

  • Print the sum.

  • Stop.

Algorithm:-

Code:-

num = 5
sum = 0
for i in range(num+1):
  sum+=i
print(sum)

Output:-

  5

  Sum is 15