Kelly said:
[...] take care of the
limits that your particular compiler imposes on the limit
of int,check <limits.h>
so that factor*factor doesn't overflow the limit
Or, knowing that factor >= 2, you can do this: factor <= num / factor
Or better still, you can do this:
max = sqrt(num);
for(factor = 2; factor <= max; factor++)
which removes the in-loop calculation completely and therefore removes the
possibility of overflow in that calculation (and yes, more optimisation
work remains to be done, but this thread isn't about optimisation).