[Solved] Prime numbers code [closed]


for (a = 2; a <= 10; a++)
{
    for (i = 2; i < a; i++)
    {
        if (a % i == 0)
        {
            m = false;
        }
    }

    if (m == true)
    {
        Console.WriteLine(a);
    }

    m = true; //<<******* Add this line
}

of course some speed up is always possible

for (a = 2; a <= 100; a++)
{
    for (i = 2; i < Math.Sqrt(a); i++) //<--- http://en.wikipedia.org/wiki/Prime_number#Trial_division
    {
        if (a % i == 0)
        {
            m = false;
            break; //<---- a is not prime, quit the inner loop immediately.
        }
    }

    if (m == true)
    {
        Console.WriteLine(a);
    }

    m = true; //<<******* Add this line
}

solved Prime numbers code [closed]