You can find many of these with googling "c++ prime number generator" etc.
Heres one from one of the first results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <cmath>
bool IsPrime(int num)
{
// no number can divide into 0
if(num == 0)
returntrue;
// make sure its not negative
num = abs(num);
for(int i = 2; i <= sqrt(num); i++)
if(num % i == 0)
returnfalse;
returntrue;
}
Haven't bother to look to see if its correct. But it's an easy topic to find. At the least you'll be able to find a heap of different ways to create one.