C#编程输出1000以内的所有素数

img

img


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 sushu= true;
                for (int j = 2; j <= i-1; j++)
                {
                    if (i % j == 0)
                    {
                        sushu= false;
                        break;
                    }
                }
                if (sushu)
                    Console.WriteLine(i);
            }
            
        }
     }
}