title: Sieve of Eratosthenes
body: <p>I read up on the sieve of Eratosthenes while solving a question on <a href="https://projecteuler.net" rel="nofollow">Project Euler</a>. I'm sure you guys know which question im talking about.
  So here's the thing. My code manages to show all the primes under 1 million correctly.
  However when i try the same implementation for 2 million it's giving me a segmentation fault...
  I have a certain idea of why the error is coming but don't know how to correct it...
  Here's the code for primes under 1 million.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main(void)
  {
     int i,k=2;
     int j;
     int n=1000000;
     int prime[2000000]={};
     for(i=0;i&lt;n;i++) // initializes the prime number array
     {
        prime[i]=i;
     }
     for(i=2;i&lt;n;i++) // Implementation of the Sieve
     {
        if(prime[i]!=0)
        { 
           for(j=2;j&lt;n;j++)
           {
              {
                 prime[j*prime[i]]=0;
                 if(prime[i]*j&gt;n)
                    break;    
              }
           }
        }
     }
     for(i=0;i&lt;n;i++) // Prints the prime numbers
        if(prime[i]!=0)
        {
           printf("%d\n"prime[i]);
        }
        return(0);
     }
  }
  </code></pre>