Even or Odd in PHP


Q. Write a PHP program to check whether a number is even or odd

<?php
// Define a number
$number = 7;

// Check if the number is even or odd
if ($number % 2 == 0) {
    echo "$number is an even number.";
} else {
    echo "$number is an odd number.";
}
?> 

Q. Write an algorithm to check even or odd number in PHP

1. Start
2. Define or read an integer value and store it in number
3. Check if number % 2 == 0
    If true, print "Even number"
    Else, print "Odd number"
4. End



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.