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;
}
}
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;
}
}