35.1k views
4 votes
Write a program that, given an integer, sums all the numbers from 1 through that integer (both inclusive). Do not include in your sum any of the intermediate numbers (1 and n inclusive) that are divisible by 5 or 7.

1 Answer

7 votes

Answer:

let n = 10;

let sum = 0;

for(i=1; i<=n; i++) {

if ((i%5) && (i%7)) {

sum += i;

}

}

console.log(`Sum 1..${n} excluding 5 and 7 multiples is ${sum}`);

Step-by-step explanation:

This is in javascript.

example output:

Sum 1..10 excluding 5 and 7 multiples is 33

User JonoJames
by
5.9k points