Multiples of 3 and 5

Problem:

Find the sum of all the multiples of 3 or 5 below 1000.


Solution:

1
2
3
4
5
 sum = 0
 for i in range(1000):
    if (i % 3 == 0 or i % 5 == 0):
        sum = sum + i
 print(sum)



Note: This problem was taken from Project Euler (www.projecteuler.net). 

Comments

Popular posts from this blog

Even Fibonacci numbers

Largest palindrome product