Just about anyone learning to program soon faces the task of having to write a program to generate a table of prime numbers. To refresh your memory, a positive integer, `p`

, is a prime number if it is not evenly divisible by any other integers other than 1 and itself. The first prime integer is defined to be 2. The next prime is 3 because it is not evenly divisible by any integers other than 1 and 3; and 4 is *not* prime because it *is* evenly divisible by 2.

You can take several approaches to generate a table of prime numbers. If you had the task of generating all prime numbers up to 50, for example, the most straightforward (and simplest) algorithm to generate such a table would simply test each integer, `p`

, for divisibility by ...

Start Free Trial

No credit card required