Computer Science, asked by pranav15032007, 2 months ago

Write a JavaScript program to accept a number and find out whether it is a multiple of 5 or 3 or 2​

Answers

Answered by khushisuriya
0

Answer:

wrote a code with javascript for this problem :

"If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

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

but the result is false and i don't know why? can you help me guys

my code is :

function multipleSum(n){    

  var sum = 0;

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

    var m3 = 3 * i;

    var m5 = 5 * i;    

    if(m3 < n  ){

      sum=sum+m3

    }

    if(m5 < n ){

      sum=sum+m5;

    }

    //if(m3 > n && m5 > n) {console.log(m3,m5,sum);break;}

  }

  return sum

}

console.log(multipleSum(1000)) //266333 but correct one is 233168 why?

Similar questions