google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Write a program in php to check given number is even or odd

Monday, April 6, 2020

Write a program in php to check given number is even or odd

Write a program in php to check given number is even or odd

Answer:
<html>
<body>
<h3>Odd or Even PHP Example</h3>
<form action="" method="post">
<label>Enter a number</label>
<input type="text" name="number" />
<input type="submit" />
</form>
</body>
</html>
<?php 
if($_POST){
$number = $_POST['number']; 
//check if the enter value is a number or throw an error
if (!(is_numeric($number) && is_int(0+$number))){
echo "<p style='color:red;'>Error: You entered a string. Please enter an Integer</p>";
die();
}
//divide the entered number by 2 
//if the reminder is 0 then the number is even otherwise the number is odd
if(($number % 2) == 0){
echo "You entered an Even number";
}else{
echo "You entered an Odd number";
}
}
?>

No comments:

Post a Comment

हिम्मत

 अंधेरे में एक करोड का हीरा गिर गया था, उसे ढूंढने के लिए पाँच रूपएं की मोमबत्ती ने सहयोग किया। अभी बताओ वह पाँच रूपएं की एक छोटी सी मोमबत्त...