home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / HITECH-C / Z8051H83.EXE / SIEVE.C < prev    next >
C/C++ Source or Header  |  1993-05-21  |  525b  |  32 lines

  1. #include    <stdio.h>
  2.  
  3. #define    TRUE    1
  4. #define    FALSE    0
  5. #define    SIZE    8190
  6.  
  7. char    flags[SIZE+1];
  8.  
  9. main()
  10. {
  11.     register int    k, j, i, count, prime;
  12.  
  13.     printf("100 iterations\n");
  14.     for(i = 1 ; i <= 100 ; i++) {
  15.         count = 0;
  16.         for(j = 0 ; j <= SIZE ; j++)
  17.             flags[j] = TRUE;
  18.         for(j = 0 ; j <= SIZE ; j++) {
  19.             if(flags[j]) {
  20.                 prime = j + j + 3;
  21.                 k = j + prime;
  22.                 while(k <= SIZE) {
  23.                     flags[k] = FALSE;
  24.                     k += prime;
  25.                 }
  26.                 count = count + 1;
  27.             }
  28.         }
  29.     }
  30.     printf("\n%d primes\n", count);
  31. }
  32.