编程实践54

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

namespace _5_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] dA;
            int i, j;
            dA = new int[100];

            for(i = 0;i<100;i++)
            {
                dA[i]=i+1;
            }
            dA[0] = 0;
            for (i = 1; i < Math.Sqrt(dA.Length);i++)
            {
                if (dA[i] != 0)
                {
                    for (j=i+1; j <dA.Length; j++)
                    {
                        if (dA[j] % dA[i] == 0)
                        {
                            dA[j] = 0;       
                        }
                    }
                }
            }

            for (i = 0; i < 100; i++)
            {
                if (dA[i] != 0)
                {
                    Console.Write(dA[i] + " ");
                }
            }

            Console.ReadKey();

        }
    }
}
原文地址:https://www.cnblogs.com/Wzqa/p/2780322.html