I am working on my test case for checking if number is odd or even and when I number is 3 then it shows Odd number but number is 24 then it still shows number as Odd number.
I am using modules Divide for checking the Odd Even number. Please have a Look at the code and let me know where I am making mistake:
<?php
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d
", $N);
fclose($stdin);
if($stdin / 2 != 0){
print("Weird");
}
else{
if(($stdin >= 2) && ($stdin <= 5)){
print("Not Weird");
}
elseif(($stdin >= 6) && ($stdin <= 20)){
print("Weird");
}
elseif($stdin > 20){
print("Not Weird");
}
}
use module operator %
instead of division
https://www.php.net/manual/en/internals2.opcodes.mod.php
24 / 2 = 12 So it will not be 0
24 % 2 = 0 since it calculates remainder ( what is left over when division has been done equally )
23 % 2 = 1 (since after dividing equally we will have 1 left