Is it a valid code for Sieve of Eratosthenes? : <p>I recently learned Sieve of Eratosthenes to find prime numbers. After knowing the method i wrote this code for it.<br>
<strong><em>Would it be a valid C++ code for Sieve of Eratosthenes?</em></strong></p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int main()
{
int n;
cin&gt;&gt;n;
bool array[n];

for(int i=2;i&lt;=n;i++)
{
    array[i]=true;
}

   for(int i=2;i&lt;=n/2;i++)
   {
      for(int j=i+1;j&lt;=n;j++)
      {
         if(array[j]==true)
         {
            if(j%i==0)
            array[j]=false;
         }
      }
   }

  for(int k=2;k&lt;=n;k++)
  {
    if(array[k]==true)
    cout&lt;&lt;k&lt;&lt;" ";
  }
}
</code></pre>

<p><strong>Thanks for help!</strong></p>
