C#打印0到100的素数

 static void Main(string[] args)
        {
              //输出1-100的素数
            bool res;
            int count = 0;
            for (int i = 1; i < 100; i++)
            {

                res = true;
                for (int j = 2; j < i; j++)
                {
                    count++;
                    res = i % j == 0 ? res = false : res = true;  
                    break;                       
                }
                if (res)
                {
                    Console.WriteLine(i);
                }
            
            }
            Console.WriteLine("循环了" + count);
            Console.ReadKey();
        }

猜你喜欢

转载自www.cnblogs.com/tianranhui/p/10118719.html
今日推荐