您的位置:首页 > 编程语言 > C#

C#求1000以内所有素数

2020-04-24 10:59 1016 查看

求1000以内所有素数,亲测有效

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

namespace helloworld
{
class Program
{
static void Main()
{
int i;
for ( i = 2; i <= 1001; i++)
{
bool isZhishu = true;
for (int j = 2; j <= i-1; j++)
{
if (i % j == 0)
{
isZhishu = false;
break;
}
}
if (isZhishu)
Console.WriteLine(i);
}

}
}
}

希望对你有帮助;

  • 点赞
  • 收藏
  • 分享
  • 文章举报
anhao_aha 发布了4 篇原创文章 · 获赞 0 · 访问量 232 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: