Is this mingw bug ?

Posted by Debanjan on Stack Overflow See other posts from Stack Overflow or by Debanjan
Published on 2010-06-16T07:48:22Z Indexed on 2010/06/16 7:52 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

Hi, I have been trying to execute this program on my migw ,through code::blocks,

#include <string.h>
#include <math.h>
#include <stdio.h>
#define N 100
int p[N / 64];
int pr[N];
int cnt;

void sieve()
{
   int i,j;
   for(i=0;i<N;i++) pr[i]=1;
   pr[0]=pr[1]=0;

   for(i=2;i<N;i++)
      if(pr[i])
        {
         p[cnt]=i; cnt++;
         for(j=i+i;j<=N;j+=i) pr[j]=0;
        }

  }

int main(){
    sieve();
    int i;
    for(i=0;i<cnt;i++)
       printf("%d ",p[i]);
    puts("");
   printf("Total number of prime numbers : %d",cnt);
  return 0;
}

In My system the output is :

7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Total number of prime numbers : 22

Which is completely insane,since I am completely sure about the implementation of my algorithm.

So I decided to try it in Ideone where it gives correct output.Can anybody point out the reason ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c