int i, j, count =0;
for (i=2; i<=100; i++)
{
for (j=1; j<=i; j++)
{
if (i % j == 0)
{
count++;
}
}
if (count == 2)
{
Console.WriteLine("This is a prime number" + i);
}
count = 0;
}
Console.ReadLine();
1. You should have the second loop condition like
j<=i
and not
j<=100
.
Actually you need to check whether the number is divisible with 1, 2.... upto the number you are comparing with (that is i).
2. Count should be 0 every time, but you are making it 0 when it is prime, inside the if condition.
So, 2, 3 are prime, and when 4 comes it does not make count 0, hence stops.
Thanks...