将开发过程常用的内容做个记录,下面资料是关于C# 计算素数的内容,希望能对大伙有用途。
using System.Collections;
…
const int LAST_CANDIDATE = 1000;
int primes = 0;
BitArray candidates = new BitArray (LAST_CANDIDATE, true);
for (int i = 2; i < LAST_CANDIDATE; i++)
{
if (candidates[i])
{
{ candidates[j] = false; }
}
}
for (int i = 1; i < LAST_CANDIDATE; i++)
{
if (candidates[i])
{
primes++;
Console.Out.WriteLine (i);
}
}
Console.Out.WriteLine
(“n” + primes + " primes found in the range 2-" + LAST_CANDIDATE);