Find the sum of natural numbers between 1-n

In this program, we will find the sum of natural numbers between 1 to n.

Steps to solve the program
  1. Take n as the last natural number as input through the user.
  2. Create a variable named total and assign its value equal to 0.
  3. Use for loop with range function to iterate over 1-n natural numbers.
  4. During each iteration add that number to the total.
  5. Print the output.
				
					n= int(input("Enter the last number: "))
total = 0

for i in range(1,n+1):
    total += i
    
print(total)
				
			

Output :

				
					55
				
			

print all odd numbers between 1 to 100

find the sum of all even numbers between 1 to n

Leave a Comment