Aztec C source - primes.c
Dave Newkirk
dcn at ihuxl.UUCP
Tue Nov 15 00:31:48 AEST 1983
/* Eratosthenes Sieve Prime Number Program */
#define TRUE 1
#define FALSE 0
#define SIZE 8190
char flags[SIZE+1] ;
main()
{
int i, prime, k, count, iter ;
printf("10 iterations\n") ;
for( iter=1 ; iter <= 10 ; iter++ ) {
count = 0 ;
for( i=0 ; i <= SIZE ; i++ )
flags[i] = TRUE ;
for( i=0 ; i<= SIZE ; i++ ) {
if( flags[i] ) {
prime = i + i + 3 ;
/* printf("\n%d", prime ) ; */
for( k=i+prime ; k <= SIZE ; k+=prime )
flags[k] = FALSE ;
count++ ;
}
}
}
printf("\n%d primes.\n", count ) ;
} /* end main */
More information about the Comp.sources.unix
mailing list