25. PHP Program to Check whether the given number is Even or Odd.
How does this program work?
- In this program you are going to learn about to check if a number is Even or Odd using PHP.
- In this program odd and even A number is even if it is perfectly divisible by 2.
- When the number is divided by 2, we use the remainder operator % to compute the remainder.
- If the remainder is zero, the number is even else the number is odd.
Here is the code
<html>
<head>
<title>PHP Program To check whether the given number is Even or Odd</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$number = $_POST['num'];
//If the remainder is zero the number is Even else the number is Odd
if($number%2 == 0)
{
echo " $number is a Even number ";
}
else
{
echo " $number is a Odd number ";
}
return 0;
}
?>
</body>
</html>