Find even and odd no in an array using PHP
i have written this program to find out even and odd numbers in an arrayPHP Function used
array()
count($array)
Loop used
for loopconditional logic used
Ifelse
<?php
$no=array(1,21,53,84,50,66,7,38,9);
$countno=count($no);
echo $countno;
for($key=0; $key<$countno; $key++)
{
if ($no[$key] % 2 == 0)
{echo "This ".$no[$key]. " is an even<br>";
}
else
{
print "This no ".$no[$key]."is an odd no <BR>";
}
}
?>
If you know some other method feel free to share in comments.
0 comments :
Post a Comment