As you SHOULD know, a prime number is a whole number
*That's larger than one
*That's divisible only by one and itself ('divisible' meaning: there's
NO remainder after division)
Here, a simple but very brute force approach would be something like this:
Code:
bool NumIsPrimer(int num)
{
if(num < 2) return false;
int sqr = sqrt(num);
int try_to_divide = 1;
while(++try_to_divide < sqr)
{
if(num % try_to_divide == 0) return false;
}
return true;
}
The thing with what you coded is that it will only work in as far as you already supply it with prime #s.
The trick is to let the program calculate whether the numbers are prime or not.