title: Sieve of Eratosthenes prime numbers up to a million c++
body: <p>So I need help with my code. For some reason it keeps crashing when I enter a number past 500,000. Here is the exact assignment. </p>
  
  <blockquote>
    <p>Implement the Sieve of Eratosthenes and use it to find all prime
    numbers less than or equal to one million. Use the result to
    prove Goldbach's Conjecture for all even integers between four and
    one million, inclusive.</p>
    
    <p>Implement a function with the following declaration:</p>
  
  <pre><code>void sieve(int array[], int num);
  </code></pre>
    
    <p>This function takes an integer array as its argument. The array
    should be initialized to the values 1 through 1000000. The
    function modifies the array so that only the prime numbers remain;
    all other values are zeroed out.</p>
    
    <p>This function must be written to accept an integer array of any
    size. You must should output for all primes numbers between 1 and
    1000000, but when I test your function it may be on an array of a
    different size.</p>
    
    <p>Implement a function with the following declaration:</p>
  
  <pre><code>void goldbach(int array[], int num);
  </code></pre>
    
    <p>This function takes the same argument as the previous function
    and displays each even integer between 4 and 1000000 with two
    prime numbers that add to it.</p>
    
    <p>The goal here is to provide an efficient implementation. This
    means no multiplication, division, or modulus when determining if
    a number is prime. It also means that the second function must find
    two primes efficiently.</p>
    
    <p>Output for your program:</p>
    
    <p>All prime numbers between 1 and 1000000
    and all even numbers between 4 and 1000000 and the two prime
    numbers that sum up to it.</p>
    
    <p>DO NOT provide output or a session record for this project!</p>
  </blockquote>
  
  <p>And here is what I have so far. If anyone could help me that would be great. </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void sieve (int array[], int num);
  
  int main()
  {
      int num;
      cout &lt;&lt; "Enter a number to calculate up to." &lt;&lt; endl;
      cin&gt;&gt; num;
      if ( num &lt; 2 )
          return 0;
  
      int array[num];
      array[0]= array[1]= 0;
      for ( int i= 2; i &lt; num; ++i )
          array[i]= i;
      sieve(array,num);
      for (int i=0; i&lt;num; i++)
          if (array[i] &gt; 0)
              cout &lt;&lt; array[i] &lt;&lt;" "&lt;&lt;endl;
      cout&lt;&lt;endl;
  
      return 0;
  }
  
  void sieve( int array[], int num )
  {
      for ( int i= 0; i &lt; num; ++i )
      {
          if ( array[i] != 0 )
          {
              for ( int j= i+i; j &lt; num; j += i )
              {
                  array[j]= 0;
              }
          }
      }
  }
  </code></pre>