Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error in cpp code

$
0
0
I have this code running in my desktop and in online compilers, when I try to submit it in SPOJ, its popping up with SIGSEGV error. Can anyone help me out, why that error occcurs?

#include <iostream>

using namespace std;

int main()
{
    long int t=0,i=0,j=0,n=0;
    cin >> t;
    const long int test=t;
    long int input[test][2],max=0,min=12;
    
    for(i=0;i<test;i++)
    {
        for(j=0;j<2;j++)
        {
            input[i][j]=0;
            cin >> input[i][j];
            if(input[i][j]>max)
            {
                max=input[i][j];
            }
            if(input[i][j]<min)
            {
                min=input[i][j];
            }
        }
    }
    
    const long int maximum = max+1;
    bool primeVector[maximum];
    
    for(int k=0;k<=max;k++)
    {
        primeVector[k]=false;
    }
    
    for(int l=2;l<=max;l++)
    {
        if(primeVector[l])
        {
            continue;
        }
        for(int m=2;(m*l)<=max;m++)
        {
           primeVector[m*l]=true; 
        }
    }
    primeVector[0]=true;    
    primeVector[1]=true;
   primeVector[2]=false;
   primeVector[3]=false;
    for(int o=0;o<test;o++)
    {
        cout << endl;
        for(int p=input[o][0];p<=input[o][1];p++)
        {
            if(!primeVector[p])
            {
                cout << p << endl;
            }
        }
    }
    return 0;
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>