0
Continuous Multiplications
The given code declares a loop and calculates the multiplication of all numbers from 1 to 10000. Make the necessary changes to break the loop when the result gets larger than 10000 and output the result. Code: res <- 1 for(x in 1:10000) { res <- res * x if(res > 10000) { break } print(res) } why does not it work, please, help..
7 odpowiedzi
+ 3
First print res then do break
+ 2
Put the if statement before multiplication
+ 2
Or just put the print in the line above the break...
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
Thank you!
now I understand, the code works !!!
0
Thanks, tried it but doesn't work.
The result is considered incorrect.
0
let num = 1;
for(i = 1; i<=100, i++;){
num*=i;
//your code goes here
if (num > 10000)
break
}
console.log(num);
0
@Prostibozenko Ilja
I have some doubt on ur suggestion .
how come num involve here when the result is stored in "i" , i think "i"should be used but include while loop.