Path: utzoo!attcan!telly!problem!compus!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac From: jac@yoko.rutgers.edu (Jonathan A. Chandross) Newsgroups: comp.sources.apple2 Subject: v001SRC015: sieve -- Compute Primes Using Eratosthenes' Sieve Message-ID: Date: 1 Dec 90 21:53:22 GMT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 61 Approved: jac@paul.rutgers.edu Submitted-by: NONE Posting-number: Volume 1, Source:15 Archive-name: util/sieve Architecture: ANY_2 Version-number: 1.00 No computer should be without a program to compute prime numbers. Here's one. Enjoy. =primes.c -/* - * - * sieve.c - * - * Eratosthenes Sieve Prime Number Program. - * - * Usage: - * seive - * - * Contributed Anonymously. Written: November 1983 - * - * Version 1.00 - * - */ - -#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 */ - - + END OF ARCHIVE