We make the entry in prime[i] be true if i is a prime
number
and false if i is not a prime number.
Initially we assume that 0 and 1 are not rpime and everything else is.
Starting with 2 we 'cross out' its multiples -4, 6, 8
etc.
We 'cross out' 4 by making primes[4]=false. We 'cross out' 6 by
making primes[6]=false.
After we have crossed out all the multiples of 2, up to
n,
we look for multiples of 3.
After we are done with the mulitples of 3, we are ready to
work
on mulitples of 4. Actually, primes[4] is false since 4 is a
multiple
of 2. That is, we already 'got' all of 4's multiples, when we got
2's.
So we don't need to bother with 4's multiples.
So we go on to multiples of 5, etc.
We continue this until we have crossed out muliples of 2, 3,
5,
up to multiples of the square root of n. (Why?)
Finally we print out those i's for which primes[i] is
true.