I am getting a segmentation error in PRIME1 on spoj. How should I eradicate it? <p>My answer to problem <a href="http://www.spoj.com/problems/PRIME1/" rel="nofollow">PRIME1</a> please explain me where am I wrong. I am receiving a segmentation error.</p> <p>here it is:</p> <pre><code> #include&lt;cstdlib&gt; #include&lt;iostream&gt; using namespace std; int main(int argc, char** argv) { int t=0,i=0,m=0,n=0; cin&gt;&gt;t; while(t--&amp;&amp;t&lt;=10) { cin&gt;&gt;m&gt;&gt;n; if(m&gt;=1&amp;&amp;n-m&lt;=100000) { int prime[n]; for(i=0;i&lt;n;i++) prime[i]=1; for (int i=2; i*i&lt;=n; i++) { if (prime[i] == true) { for (int j=i*2; j&lt;=n; j += i) prime[j] = false; } } for (int k=m+1; k&lt;n; k++) if (prime[k]) cout &lt;&lt;k&lt;&lt;endl; } } return 0; } </code></pre>