我有一个条件语句来检查PHP中的数字是否为奇数或偶数
<?php
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $N);
fclose($stdin);
function weird_or_not($N) {
//check that n is between 1 and 100
if ($N >= 1 && $N <= 100) {
//check if n is even
if ($N % 2 == 0) {
// check if n is in the inclusive range 2 - 5
if ($N >= 2 && $N <= 5) {
echo 'Not Weird';
}
// check if n is in the inclusive range 6 - 20
elseif ($N >= 6 && $N <= 20) {
echo 'Weird';
}
// check if n is greater than 20
elseif ($N > 20) {
echo 'Not Weird';
}
}
// otherwise n is odd
else {
echo 'Weird';
echo $N % 2;
}
}
}
echo weird_or_not($stdin);
?>
当我输入一个偶数时,它会打印出“怪异”,而当我打印出$ N%2时,对于任何偶数,当结果应为0时,结果为1。为什么是偶数呢?模2的模数应该返回0时返回1?