If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
It should be really easy to find one: just search on Google for "Prime Number Algorithm."
This is a pretty terrible algorithm, but it'll do...
Code:
int i, j, found = 0;
for (i = 2; i < PRIME_MAX; i++, found = 0)
{
for (j = 2; j < ((int)sqrt(i))+1; j++)
{
if (i % j == 0)
{
found = 1;
break;
}
}
if (found)
cout << "Hey! " << i << " is a prime number!\n";
}
"Against stupidity, the gods themselves contend in vain" (Schiller)