1 using System; 2 public class PrimeFilter 3 { 4 public static void Main( string [] args ) 5 { 6 int N = 100; 7 bool [] a = new bool[N+1];//bool数组 8 9 for( int i=2; i<=N; i++ ) 10 a[i]=true; 11 12 for( int i=2; i<N; i++ ) 13 { 14 if(a[i]){ 15 for( int j=i*2; j<=N; j+=i ) 16 a[j]=false; 17 } 18 } 19 20 for( int i=2; i<=N; i++) 21 if( a[i] ) Console.Write( i + " " ); 22 23 Console.ReadLine();//暂停 24 } 25 }