Python program to print sum of odd numbers between 1 to 100 (1 + 3 + 5 + .... + 99).
Concept to learn: Python while loop
# Python program to print sum of odd numbers between 1 to 100 (1+3+5...+99) using while loop.
sum = 0
num = 1
while(num <= 100):
sum = sum + num
num = num + 2
print("Sum of odd numbers between 1 to 100 is ", sum)
num = 1
while(num <= 100):
sum = sum + num
num = num + 2
print("Sum of odd numbers between 1 to 100 is ", sum)
Output of Program
Sum of odd numbers between 1 to 100 is 2500
No comments:
Post a Comment