// Find prime numbers between 2 and 100.
using System;
class Prime {
static void Main() {
int i, j;
bool isprime;
for(i=2; i < 100; i++) {
isprime = true;
// See if the number is evenly divisible.
for(j=2; j <= i/j; j++)
// If i is evenly divisible, then it’s not prime.
if((i%j) == 0) isprime = false;
if(isprime)
Console.WriteLine(i + " is prime.");
}
}
}
How does i/j test if the number is evenly divisible? and take the number 2 for example: i = 2 and j = 2, 2/2 = 1 so j is not incremented. 2%2 == 0 so shouldn't it be set to false even though 2 is a prime number?
Many Thanks!