function testEven($pArg){
if(is_int($pArg) === true){
$p = ($pArg % 2);
if($p === 0){
print "The input '".$pArg."' is even.<br>";
}else{
print "The input '".$pArg."' is odd.<br>";
}
}else{
print "The input '".$pArg."' is not a number.<br>";
}
}
The print is there for testing purposes, hence in practice it becomes:
function testEven($pArg){
if(is_int($pArg)=== true){
return $pArg%2;
}
return false;
}
$(document).ready(function(){
$("#btn_even_odd").click(function(){
var arr = ['Even','Odd'];
var num_even_odd = $("#num_even_odd").val();
$("#ans_even_odd").html(arr[num_even_odd % 2]);
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Check Even Or Odd Number Without Use Condition And Loop Statement.</title>
</head>
<body>
<h4>Check Even Or Odd Number Without Use Condition And Loop Statement.</h4>
<table>
<tr>
<th>Enter A Number :</th>
<td><input type="text" name="num_even_odd" id="num_even_odd" placeholder="Enter Only Number"></td>
</tr>
<tr>
<th>Your Answer Is :</th>
<td id="ans_even_odd" style="font-size:15px;color:gray;font-weight:900;"></td>
</tr>
<tr>
<td><input type="button" name="btn_even_odd" id="btn_even_odd" value="submit"></td>
</tr>
</table>
</body>
</html>
<?php
// Recursive function to check whether
// the number is Even or Odd
function check($number){
if($number == 0)
return 1;
else if($number == 1)
return 0;
else if($number<0)
return check(-$number);
else
return check($number-2);
}
// Check the number odd or even
$number = 35;
if(check($number))
echo "Even";
else
echo "Odd";
?>