Tuesday, 6 November 2012

Sum of odd numbers via for loop


The sum of all odd numbers from 1 to 50. Using for loop.

sum=0
for i in range(1,50):
    if i%2==1:
        sum=sum+i
print sum

No comments:

Post a Comment