c has an indeterminate value in your for loop here:
for(int c; x < c; c++)
^
you need to initialize it to a value for example:
for(int c=2; x < c; c++)
it will need to be greater than 0
(perhaps 2 since you probably don't want 1 as a divisor) since you are using it in the modulus operation here:
if (x%c==0)
and modulus by 0
is undefined behavior as per the draft C++ standard section 5.6
Multiplicative operators paragraph 4 says:
[...]If the second operand of / or % is zero the behavior is undefined.[...]
It looks like you may have flipped your ending condition and it should go from c < x
instead of x < c
.
No comments:
Post a Comment