home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / misc / smc203.ark / SIEVE.C < prev    next >
Encoding:
Text File  |  1983-07-28  |  1.1 KB  |  39 lines

  1. /* standard "sieve of eratosthenes" generation of primes *
  2.  * keyboard entered by frank gaude'  08/02/83              */
  3.  
  4. #include "stdio80.h"
  5.  
  6. #define SIZE      8190    /* size of number array */
  7. #define FALSE         0
  8. #define TRUE       1
  9. #define NTIMES      10
  10.  
  11.     extern  printf(),exit();
  12.     char    flag[SIZE + 1];
  13.  
  14. main()        /* compute primes using sieve of eratostenes */
  15. {
  16.     int    i, j, k, count, prime;
  17.  
  18.     printf("10 iterations: ");
  19.  
  20.     for (i = 1; i <= NTIMES; i++) {             /* do program ntimes */
  21.         count = 0;                 /* prime counter     */
  22.         for (j = 0; j <= SIZE; j++)         /* set all flags true*/
  23.             flag[j] = TRUE;                  
  24.         for (j = 0; j <= SIZE; j++) {            
  25.             if (flag[j] == TRUE) {         /* found a prime     */
  26.                 prime = j + j + 3;     /* twice index + 3   */
  27.                 printf("\n%d",prime);    /* print prime       */
  28.                 for (k = j + prime; k <= SIZE; k += prime)
  29.                     flag[k] = FALSE; /* discard multiples */
  30.                 count++;         /* primes found      */
  31.             }
  32.         }
  33.     }
  34.  
  35.     printf("%d primes.\n", count);
  36.     exit(0);
  37. }
  38. 
  39. ABS     C   ;ÇCALL    ASM <─)CALL    REL BÇ