求素数(网上找的,仅自用,非原创)

Posted v123ve

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求素数(网上找的,仅自用,非原创)相关的知识,希望对你有一定的参考价值。

using System;
namespace Other_Features
{
public class Prime
{
public int number;
public Prime(int n)
{
if(isPrime(n))
this.number=n;
else
throw new Exception (n+" is not a prime.");
}
public static Prime operator ++ (Prime orig)
{
bool succeeded =false;
while(!succeeded)
succeeded=isPrime(++orig.number );
return orig;
}
public static bool isPrime(int number)
{
int max=(int)(number/2+1);
for(int i=2;i<max;++i)
if(number%i==0)
return false;
return true;
}
public static void Main()
{
Prime p=new Prime (1);
for(int i=0;i<100;++i)
{
Console.WriteLine (p.number);
++p;
}
}
}
}

以上是关于求素数(网上找的,仅自用,非原创)的主要内容,如果未能解决你的问题,请参考以下文章

递归方法求阶乘字符串反转(网上找的,仅自用,非原创)

求平均成绩使用二维数组(网上找的,仅自用,非原创)

choosesubject(网上找的,仅自用,非原创)

输出随机数(网上找的,仅自用,非原创)

棋盘(网上找的,仅自用,非原创)

关闭特定程序(网上找的,仅自用,非原创)