The code below is part of the title fuction. What has been omitted is setting all elements from 2 to a user entered bound in prime[ ] to true and then setting all elements from j=2 to 2*j< bound to false thus ruling out all even numbers as prime. This last code finds all primes after 2 and before bound and works properly.
[CODE=cpp]
int p=3
int p = 3;
while (p<= bound/2)
{
for(int j=2;p*j<bound;j ++)
prime [p*j] = false;//multiples of p are not prime
do ++p;
while(!prime[p]);
};
[/CODE]
What i cannot understand is how the last line determines when p is again prime
[CODE=cpp]
int p=3
int p = 3;
while (p<= bound/2)
{
for(int j=2;p*j<bound;j ++)
prime [p*j] = false;//multiples of p are not prime
do ++p;
while(!prime[p]);
};
[/CODE]
What i cannot understand is how the last line determines when p is again prime
Comment