Code
//
// primes
//
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int COUNT = 20001;
int numbers[COUNT];
int candidate;
int primes;
bool isprime;
numbers[0]=2; // first even prime
numbers[1]=3; // first odd prime
primes=2; // I have two primes
candidate=5;
while(primes < COUNT) {
isprime=true;
for(int index=0 ; index < primes && isprime; index++)
if(candidate % numbers[index] == 0 ) isprime=false;
if(isprime) {
numbers[primes]=candidate;
primes++;
}
candidate+=2;
}
//
// print every 1000 th prime number
//
cout << "Computed Primes are " << endl;
for(int index=1000; index < 20001; index+=1000)
cout << index << "\t" << numbers[index] << endl;
system("pause");
return 0;
}