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