home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 31 < prev    next >
Encoding:
Text File  |  1990-12-02  |  1.4 KB  |  72 lines

  1. Path: wuarchive!swbatl!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC015:  sieve -- Compute Primes Using Eratosthenes' Sieve
  5. Message-ID: <Dec.1.16.53.21.1990.24783@yoko.rutgers.edu>
  6. Date: 1 Dec 90 21:53:22 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 61
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: NONE
  13. Posting-number: Volume 1, Source:15
  14. Archive-name: util/sieve
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. No computer should be without a program to compute prime numbers.
  19. Here's one.
  20.  
  21. Enjoy.
  22.  
  23. =primes.c
  24. -/*
  25. - *
  26. - * sieve.c
  27. - *
  28. - * Eratosthenes Sieve Prime Number Program.
  29. - *
  30. - * Usage:
  31. - *    seive 
  32. - *
  33. - * Contributed Anonymously.  Written: November 1983
  34. - *
  35. - * Version 1.00
  36. - *
  37. - */
  38. -
  39. -#define TRUE  1
  40. -#define FALSE 0
  41. -#define SIZE 8190 
  42. -
  43. -char flags[SIZE+1] ;
  44. -
  45. -main()
  46. -{
  47. -   int i, prime, k, count, iter ;
  48. -
  49. -   printf("10 iterations\n") ;
  50. -
  51. -   for( iter=1 ; iter <= 10 ; iter++ ) {
  52. -      count = 0 ;
  53. -      for( i=0 ; i <= SIZE ; i++ )
  54. -         flags[i] = TRUE ;
  55. -      for( i=0 ; i<= SIZE ; i++ ) {
  56. -         if( flags[i] ) {
  57. -            prime = i + i + 3 ;
  58. -/*            printf("\n%d", prime ) ; */
  59. -            for( k=i+prime ; k <= SIZE ; k+=prime )
  60. -               flags[k] = FALSE ;
  61. -            count++ ;
  62. -         }
  63. -      }
  64. -   }
  65. -
  66. -   printf("\n%d primes.\n", count ) ;
  67. -
  68. -} /* end main */
  69. -
  70. -
  71. + END OF ARCHIVE
  72.