Function sieveOfEratosthenes must find all prime numbers up to 10,000 by marking an array in the manner described below so that there is a P above each prime number, and there is an N above each non-prime number. code example
Example: sieve of eratosthenes c++
#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}
int main()
{
int n = 30;
cout << "Following are the prime numbers smaller "
<< " than or equal to " << n << endl;
SieveOfEratosthenes(n);
return 0;
}