Harold Blake wrote:I am trying to make a prime number program...
Some other things for you:
1. Line 13 is inefficient because the value you're checking against is far too high. Have a think what a better one might be.
2. If you check whether the number (
n) is odd
before you enter the loop, you don't have to check for any
even factors, because an odd number can't possibly divide exactly by an even number. And if
n isn't odd, then it
can't be prime, can it?
3. (a bit more advanced) In fact, you only need to check
prime factors - ie, factors which are themselves prime numbers. The reason being that if a number divides by, say 15 (which is
not prime), then you already know that it
must divide by either 3 or 5, which you've hopefully checked for already.
Have a think how you could use that to make your program more efficient.
HIH
Winston