In this program, we will calculate the sum of odd numbers from 1-100.
Steps to solve the program
- Create a variable to calculate the sum and assign its value equal to 0.
- Use for loop to iterate over all numbers between 1-100.
- If the number is odd then add it to the variable created.
- Print the output.
total = 0
for i in range(1,101):
if i%2 != 0:
total += i
print("Sum of odd numbers: ",total)
Output :
Sum of odd numbers: 2500