Re: prime number generator
Because inside IF: number variable changes and divisor stays on the same position it was left by the previous number value until number variable checks as a "prime" number.
For example we try number = 24: by the time number equals 27 divisor is already 14. So for number=27 we run divisor from 14 till 26 and 27 never is fully divided so it gets into the list of primes that is obviously wrong.
Reinitialize divisor every time you change the number.
It's all can be clearly seen using any debugger...
Re: prime number generator
To speed it up, you can try dividing only by odd numbers less than half the target number. To speed it up even more, store the primes already calculated and divide only by them (again for values up to half the target). And so-on ;-)
Doing more things faster is no substitute for doing the right things...
S. R. Covey
Re: prime number generator
Xeel,
That was indeed the problem. Thanks very much.
Jeff