Table of Contents#### Download Safari Books Online apps: Apple iOS | Android | BlackBerry

### Boolean Variables

Entire Site

Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

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 all integers from `2` through `p-1`. If any such integer evenly divided `p`, then `p` would not be prime; otherwise, it would be a prime number.