//拼写对不对不保证,没环境int[100] Get100Primes
{
int[] Primes=new int[100]();Primes[0]=2;
Primes[1]=3;
int count=2;for(int i=1;;i++)
{
if(isPrime(Primes,count, 6i+1))
count++;
if(count==100)
return Primes;if(isPrime(Primes,count, 6i-1))
count++;
if(count==100)
return Primes;
}}bool isPrime(int[] primes, int count,int num)
{for(int i=0;i<count;i++)
{
if(num%primes[i]==0)
return false;}
return true;
}
{
int[] Primes=new int[100]();Primes[0]=2;
Primes[1]=3;
int count=2;for(int i=1;;i++)
{
if(isPrime(Primes,count, 6i+1))
count++;
if(count==100)
return Primes;if(isPrime(Primes,count, 6i-1))
count++;
if(count==100)
return Primes;
}}bool isPrime(int[] primes, int count,int num)
{for(int i=0;i<count;i++)
{
if(num%primes[i]==0)
return false;}
return true;
}
const int COUNT = 100;
int nCount = 0;
int nCurrent = 2;
while (nCount < COUNT)
{
if (IsPrime(nCurrent))
{
richTextBox2.Text += nCurrent.ToString() + "\n"; //输出质数
nCount++;
}
nCurrent++;
} public bool IsPrime(int n)
{
for (int i = 2; i <= Math.Sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
PS:我觉得楼主在学会编写这个程序之前,更应该学会的是如何使用搜索引擎