home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 204_01 / sieve.c < prev    next >
Text File  |  1979-12-31  |  512b  |  30 lines

  1.  
  2. #define true 1
  3. #define false 0
  4. #define size 8190
  5. #define sizepl 8191
  6.  
  7. char    flags[sizepl];
  8.  
  9. main() {
  10.     int i,prime,k,count,iter;
  11.     printf("10 iterations\n");
  12.     for(iter=1;iter<= 10;iter++){
  13.         count=0;
  14.         for(i = 0; i<=size;i++)
  15.             flags[i]=true;
  16.         for(i=0;i <= size; i++){
  17.             if(flags[i]){
  18.                 prime = i+i+3;
  19.                 k=i+prime;
  20.                     while(k<=size){
  21.                         flags[k] = false;
  22.                         k += prime;
  23.                         }
  24.                     count = count+1;
  25.                 }
  26.             }
  27.         }
  28.     printf("\n%d primes\n",count);
  29.     }
  30.