PHP Program - Find Even and odd Number

We will get $num variable value by using $_post method.

if($num%2==0) condition is used to Find Even and odd Number in below PHP Program.

 

Example :

<?php
if(isset($_POST['submit']))
{
$num=$_POST['num'];
if($num%2==0){
$result= "$num is a even number.";
}
else
{
$result= "$num is a odd number.";
}
}else
{
$result="";
}

?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Maths Program - Find Even and odd Number by aryatechno</title>
</head>
<body>
<table>
<form name="find" method="post">
<tr>
<td colspan="2"><strong>Find Even and odd Number program</strong></td>
</tr>
<tr>
<td>Enter Number :</td>
<td><input type="text" name="num" value="<?=$_POST['num'] ?>" required></td>
</tr>

<tr>
<td></td>
<td><input type="submit" value="Find Even/Odd" name="submit" /></td>
</tr>
<tr>
<td colspan="2"><strong><?=$result ?></strong></td>
</tr>

</form>
</table>
</body>
</html>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

42001