int i, j;
for( i=2; i < 1000; i++) // Iterates through the possible primes from 2 to 1000
{
for( j=2; i/j; j++) // Iterates through possible divisors for all i
{
if(!(i%j)) break; // If i mod j is NOT 0 (if it is possible to divide i by j without getting decimals), then the number is a prime
if(j>(i/j)) cout<<i<<" is prime\n"; // if j has iterated far enough to conclude that after this point there are no possible divisors to divide i into an integer value, it is a prime
}
}
We are basically concluding that you CANNOT have higher divisors j for i above i/j, and if it has gone as far to check that, we can conclude that up to that point they have no subdivisors and are therefor primes.
EXAMPLE:
j = 2
17/2 = 8.5
j = 3
17/3 = 5 + 2/3
j = 4
17/4 = 4 + 1/4
j = 5
5 > 17 / 5
5 > 3 + 2/5
After this point all subdivisors will give decimals in their results, even for non-primes.