Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Prime Number Algorithm

Name: Anonymous 2008-12-08 21:47

/prog/ I'm very deeply stressed at the moment. I have an assignment due tomorrow morning, a prime number algorithm. I know I screwed it up badly, and I'm not even sure if I am on the right track. If there are any capable c++ programmers on /prog/ right now, think you could lend a gal a hand?

Here is a copy of my current code:

#include <iostream>
using namespace std;

int main()
{
    int s;
    int p;
    long PrimeStatus[100001];
    PrimeStatus[s] = 1;
    long MAX_PRIME_CHECK = 100000;

    for(int s = 1; s < MAX_PRIME_CHECK; s++)
    {
        if(p > 2)
        {
            PrimeStatus[p] = 1;
            return 0;
        }
       
        else if(p <= 2)
        {
            if(PrimeStatus[p] = 1)
            {
                PrimeStatus[p] = 1;
                return 0;
            }
           
            else if(PrimeStatus[p] = 0)
            {
                if(p%(p-1) == 0)
                {
                    PrimeStatus[p] = 0;
                    return 0;
                }
               
                else while(p%(p-1) != 0)
                {
                    p = p-1;
                }
               
                if(p%(p-1) == 0)
                {
                    PrimeStatus[p] = 0;
                    return 0;
                }
            }
        }
    for(p = 1; s = 0; p++)
    {
        cout << PrimeStatus[p] << endl;
    }
    return 0;
    }
}

Name: Anonymous 2008-12-12 4:06

>>38
In English please, lol. I understood 'factor' and 'prime', but not much else. One hint I learnt from an interviewer was try to explain it to your grandmother, or your 5 year old niece.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List