输出1~100的素数

        public static void Main(string[] args)
        {
            
            for (int i = 2; i <= 100; i++) {//最小的素数(质数)是2
                bool a = true;
                for (int j = 2; j <= i - 1; j++) {//能够整除1和本身之外的数,不是质数
                    if (i % j == 0) {
                        a = false;
                        break;//跳出j循环
                    }
                }
                if (a) {//a为true,则输出
                    Console.WriteLine(i);
                }                
            }
            Console.ReadKey();
        }

 

相关文章:

  • 2022-01-17
  • 2021-11-26
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
  • 2021-12-21
相关资源
相似解决方案