我在处理这个 C++ 代码时遇到了问题。整数num
是一个我想检查它是否是素数的数字。然而这个程序总是返回假。这可能很简单,但我找不到任何东西。
for(int i=2;i<num;i++){ //primes are allowed to be divided by 1 so we start at 2
if(num % i == 0){ //can be divided by a number other than itself or 1 so we trip out
return false;
} else if(i == num){ //if we've already done checks as high as possible and not tripped out yet then report success
return true;
}
}