Generating Prime Numbers using an Array -Kochan Programming in C

No this is really great you've really cleared it up for me! I think where I went wrong was the expression:

p /prime[i] >= prime[i]; 

because I was subbing in p=5 and [i] = 3; which would make the expression false. But I interpreted as:

for (i = 1; isPrime && p/prime[i] >= prime[i]; i++) { if (p % prime[i] == 0) { isPrime = 0; } } *the expression being false would cause the program to skip over this block of code

whereas:

for (i = 1; isPrime && p / prime[i] >= prime[i]; i++)

if (p % prime[i] == 0)
{
     isPrime = 0;
} 

would break the for loop then proceed directly to the following if statement.

/r/C_Programming Thread Parent