一些相关的示例

求在100以内的所有素数(质数)

bool flag = true;
for (int m = 2; m <= 100; m++)
{
    for (int i = 2; i < m; i++)
    {
        if (m % i == 0)
        {
            flag = false;
            break;
        }
        else
            flag = true;
    }
    if (flag == true)
        Console.Write(m + " ");
}
Contributors: FHL