Factors of 2: 1, 2, ?
As for grumpy
Quote:
|
Originally Posted by grumpy
That code would be thrown out in any serious code review
|
Quote:
|
Originally Posted by me
How's this for a first attempt?
|
I got my answer, I guess I should have known better than to ask further questions.
Regardless,
bool isprime(int n)
{
if (n <= 1) return false;
if (n == 2) return true; // stays till someone comes up with another factor of 2
for (int i = 3; i <= n/2; i++)
if (n % i == 0)
return false;
return true;
}