#include #include //use them bits! set them up as defines #define set_bit( mem, index ) (((char *)( mem ))[ index / 8] |= ( 1 << ( index % 8 ))) #define test_bit( mem, index ) (((char *)( mem ))[ index / 8] & ( 1 << ( index % 8 ))) #define clear_bit( mem, index ) (((char *)( mem ))[ index / 8] &= ~( 1 << ( index % 8 ))) int main() { int limit = 100; int i, j, sqrt_limit; //allocate the memory void *primes = malloc (limit/8+1); if (primes ==NULL) return; //setup the sieve for (i=2;i<=limit;i++) set_bit(primes,i); printf("List created\n"); sqrt_limit=(int)sqrt(limit); //see comments in prime2.c for (i=2;i<=sqrt_limit;i++) if (test_bit(primes,i)) for (j=i*2;j<=limit;j+=i) clear_bit(primes,j); for (i=2;i<=limit;i++) if (test_bit(primes,i)) printf("%d ",i); free (primes); return 1; }