# prime number prog. need help

This is a discussion on prime number prog. need help within the C Programming forums, part of the General Programming Boards category; heres the question You can use an array of bit-field structures as the problem states, or just a simple array ...

1. ## prime number prog. need help

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?

2. Code:
`if( (p[k] && (1<<i)) == 0) printf( "%d\n", i);`
Should that be a bitwise AND instead of a logical AND?

3. wow thanks.. that did it!

4. > (1<<i)
This isn't going to do anything meaningful for values of i past 31