100以内所有孪生质数


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//找出100以内的所有孪生质数的代码
namespace luanshengzhishu
{
class Program
{
static void Main(string[] args)
{
for(int i=2;i<97;i++)
{
if (panduan(i) == true && panduan(i + 2) == true)
{
Console.WriteLine("找到一对孪生质数,是{0},{1}",i,i+2);
}
}
}

static bool panduan(int x)//该函数用来判断一个数字是否质数
{ bool yesorno;
int i;
for (i = 2; i < x; i++)
{
if (x % i == 0)
{
break;
}
}
if (i == x)
{
yesorno=true;
}
else
{
yesorno=false;
}
return yesorno;
}


}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM