Search for the Sieve Algorithm on the Internet. It is very simple and used for benchmarking. Most examples are written in C, which will compile in C++.
Whats the C++ code for finding the Prime numbers less than 50?
the code below finds the prime numbers less than 50:
void FindPrimes()
{
bool bZeroReminder;
for(int nNumber=2;nNumber%26lt;50;nNumber++)
{
bZeroReminder=false;
for(int nLastNumber=2;nLastNumber%26lt;nNumber;nLastN...
{
if (0==(nNumber % nLastNumber))
{
bZeroReminder=true;
break;
}
}
if (!bZeroReminer)
{
/* Do the action. the nNumber contains a prime No. */
}
}
}
Reply:7!?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment