Segmentation Fault?

Posted by user336808 on Stack Overflow See other posts from Stack Overflow or by user336808
Published on 2010-05-09T21:27:51Z Indexed on 2010/05/09 21:48 UTC
Read the original article Hit count: 249

Filed under:
|
|

Hello, when I run this program while inputting a number greater than 46348, I get a segmentation fault. For any values below it, the program works perfectly. I am using CodeBlocks 8.02 on Ubuntu 10.04 64-bit. The code is as follows:

int main()
{

    int number = 46348;
    vector<bool> sieve(number+1,false);
    vector<int> primes;
    sieve[0] = true;
    sieve[1] = true;

    for(int i = 2; i <= number; i++)
    {
        if(sieve[i]==false)
        {
            primes.push_back(i);
            int temp = i*i;
            while(temp <= number)
            {
                sieve[temp] = true;
                temp = temp + i;
            }
        }
    }

    for(int i = 0; i < primes.size(); i++)
        cout << primes[i] << " ";

    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about segmentation-fault