using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day014
{
class Program
{
static void Main(string[] args)
{
//求质数 :只能被1和本身整除的数
for (int i = 2; i < 100; i++) //循环范围
{
bool flag = true; //设置一个bool 类型的值,判断是不是质数
for (int j = 2; j < i; j++)//第二个循环
{
if (i%j==0) //能被整除就不是质数
{
flag = false; //判断不是
break; //跳出第二层循环,回到第一层
}
}
if (flag) //判断是不是质数
{
Console.WriteLine("质数"+i);
}
}
Console.ReadKey(); //阅读控制板,按任意键退出(不然直接闪退了)
}
}
}
c#求质数(简化版)
最新推荐文章于 2024-02-27 10:08:53 发布