heres the question
You can use an array of bit-field structures as the problem states, or just a simple array of int instead. Either way, in the loop which will go i=2..31999, use div() from stdlib.h to produce the array index and bit number, e.g. r = div(i,32); then r.quot is the array index and r.rem is the bit position (0...31).
heres my code
PHP Code:
#include <stdio.h>
#include <stdlib.h>
int p[1000];
int main(void)
{
int i,j;
int m,k;
div_t d;
for (i =2; i<300; i++)
{
d = div( i, 300);
m = d.rem;
k = d.quot;
if( (p[k] & (1<<m)) != 0) continue;
for( j = 2*i; j < 300; j += i); p[k] |= ( 1<<j );
}
for( i = 2; i < 300; ++i)
{
if( (p[k] && (1<<i)) == 0) printf( "%d\n", i);
}
return 0;
}
it compiles but its not printing anything?
anyone know why?