multiply numbers if they meet a condition...

mathspace shared this question 2 years ago

if i have a list of numbers b through o, and a boolean identifier checks if they are prime or not. (called bprime, through oprime).

How can I multiply the number b through o, but only if they are prime?

Would i use an if statement...

if(bprime, b*if(cprime, ..... ? I can't seem to get this to work if this is the correct approach.

Comments (2)


Maybe you you could use the command KeepIf() in combination witth IsPrime to create a list with only the primes of the initial numbers; KeepIf(IsPrime(n), n, list)Then you can mulpiply elements as you want.


or if(isprime(b),b,1)*if(isprime(o),o,1)

© 2020 International GeoGebra Institute