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;
}


}
}

posted on 2018-12-25 14:21  萌新菜鸟  阅读(2925)  评论(0编辑  收藏  举报

导航