We read in math Odd and Even numbers that is Odd numbers are whole numbers that cannot be divided exactly into pairs and Any number that can be exactly divided by 2 is called as an even number.
Example :
Odd Number – 1, 3, 5, 7, 9, 11, 13, 15……
Even Number – 2, 4, 6, 8, 10, 12, 14, 16…..
and it’s easy to say which is odd number or which is even number if number is small or below 100,but think if number is large such as in 4-5 digit (37987) it’s difficult to identify number type, let’s take you are little more genius and may be you can identify these number to but if number is really big like 20-30 digit then i’m sure it’s difficult to divide and know the number type, so here come program in just few lines you can determine a given number is odd or even it doesn’t matter length of number.
Let’s see the code-
<?php
$n = 572890189003792722915783281812289437; // user input value
if($n%2 == 0){
echo "Even";
}
else{
echo "Odd";
}
Explanation :
$n = user input value – it’s your desired number
if($n%2 == 0) = here we are using modulo operator (%) “The modulo division operator produces the remainder of an integer division” so we basically checking that any number is remaining or not by modulo 2 ,if there is no remainder then given number is “Even” else “Odd”.