sum of all numbers from 1 to 1000 that are multiples of 3 and 5 code example
Example 1: find the sum of all the multiples of 3 or 5 below 1000 python
nums = [3, 5]
result = 0
for i in range(0,1000):
if i%3 == 0 or i%5 == 0:
result += i
print(result)
Example 2: Sum of all the multiples of 3 or 5
const findSum = n => {
let countArr = []
for(let i = 0; i <= n; i++) countArr.push(i)
let finalArr = countArr.map(digit => {
if(digit % 3 === 0 || digit % 5 === 0) return digit
else return 0
}).reduce((acc , curr) => acc + curr)
return finalArr
}
console.log(findSum(10))