programming-examples/php/Basics/PHP program to check whether a given number is an ugly number..php

31 lines
583 B
PHP
Raw Normal View History

2019-11-18 14:44:36 +01:00
<?php
function is_ugly($num)
{
$z = $num;
if ($num == 0)
{
return "$num is not an Ugly number";
}
$x = array(2, 3, 5);
foreach ($x as $i)
{
while ($num % $i == 0)
{
$num /= $i;
}
}
if ($num==1)
{
return "$z is an Ugly number";
}
else
{
return "$z is not an Ugly number";
}
}
print(is_ugly(12)."\n");
print(is_ugly(7)."\n");
?>