Floating-point arithmetic
Be careful about mixing integer and floating-point arithmetic. How not to test for primeness:
- int d = 2;
while (d <= sqrt(n) && n % d != 0)
++d;
if (d > sqrt(n)) { /* n is prime */ }
This might fail, for example, if sqrt(25) were to yield 4.9999999