Showing posts with label Sum of first n natural numbers. Show all posts
Showing posts with label Sum of first n natural numbers. Show all posts

Sum of first n natural numbers

# Sum of first n natural numbers

Nterms = int(input("Enter number of terms:"))

total = 0
for idx in range(1, Nterms+1,1):
total += idx

print("Sum of first",Nterms,"natural numbers = ", total)