Wednesday, August 8, 2018

phpMyPassion

PHP Program To Find Odd Even Number



"Find odd even number " is the basic PHP program for a PHP learner. As you all aware, Odd numbers are not divisible by 2 and Even numbers are divisible by 2. 

Example :
    Odd number: 3, 5, 7, 9,11
    Even number: 2, 4, 6, 8, 10 

So here I am gonna explain it with a simple PHP program.

Odd Even Number Program :-


<?php

$number=22;

if($number%2==0)
{
 echo "22 is an even number"; 
}
else
{
 echo "22 is not odd number";
} 

?>

Output :-

22 is an even number


You can also do this by defining a PHP function to check a number is odd or even as below -



PHP function to check odd even number :-


<?php
function checkOddEven($num)
{
   if($num%2==0)
   {
     $result = "Even number"; 
   }
   else
   {
     $result = "Odd number";
   }
   retrun $result;
}

echo checkOddEven(43);
?>

Output :-

Odd number


About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about PHP programming. Here you will find a hug of information on web development, web design, PHP and Latest technology.

Subscribe to this Blog via Email :