Skip to main content

primes in arrays

2 replies [Last post]
aequitas201
Offline
Joined: 2007-10-17

does anyone know how to filter non-prime numbers out out of an array and replace them with zero's while leaving all of the prime numbers untouched and in the same position they had started at?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aequitas201
Offline
Joined: 2007-10-17

also without using multiplication, division, or mod in the process

mwp
Offline
Joined: 2006-12-05

Have a look at Eratosthenes' sieve (http://www.faust.fr.bw.schule.de/mhb/eratosiv.htm).