find Armstrong number in php
<?
armstrong(9999);
function armstrong($maximum_number)
{
$sum=0;
print("Armstrong numbers between 0 to $maximum_number are: ");
for($i=0; $i<=$maximum_number; $i++)
{
$num=$i;
$sum=0;
$len=strlen($i); //Length of number i.e number of digits in a number
while($num>0)
{
$rem=$num%10;
$power=pow($rem,$len);//Raise to the power of length of each digit in a number.
$sum=$sum+$power; //Sum of power of all digits of a number
$num=$num/10; // Calculate next number
}
if($sum==$i)
{
echo $i . "= Yes <br/>";
}
}
}
?>
<?
armstrong(9999);
function armstrong($maximum_number)
{
$sum=0;
print("Armstrong numbers between 0 to $maximum_number are: ");
for($i=0; $i<=$maximum_number; $i++)
{
$num=$i;
$sum=0;
$len=strlen($i); //Length of number i.e number of digits in a number
while($num>0)
{
$rem=$num%10;
$power=pow($rem,$len);//Raise to the power of length of each digit in a number.
$sum=$sum+$power; //Sum of power of all digits of a number
$num=$num/10; // Calculate next number
}
if($sum==$i)
{
echo $i . "= Yes <br/>";
}
}
}
?>
<?
armstrong(9999);
function armstrong($maximum_number)
{
$sum=0;
print("Armstrong numbers between 0 to $maximum_number are: ");
for($i=0; $i<=$maximum_number; $i++)
{
$num=$i;
$sum=0;
$len=strlen($i); //Length of number i.e number of digits in a number
while($num>0)
{
$rem=$num%10;
$power=pow($rem,$len);//Raise to the power of length of each digit in a number.
$sum=$sum+$power; //Sum of power of all digits of a number
$num=$num/10; // Calculate next number
}
if($sum==$i)
{
echo $i . "= Yes <br/>";
}
}
}
?>
<?
armstrong(9999);
function armstrong($maximum_number)
{
$sum=0;
print("Armstrong numbers between 0 to $maximum_number are: ");
for($i=0; $i<=$maximum_number; $i++)
{
$num=$i;
$sum=0;
$len=strlen($i); //Length of number i.e number of digits in a number
while($num>0)
{
$rem=$num%10;
$power=pow($rem,$len);//Raise to the power of length of each digit in a number.
$sum=$sum+$power; //Sum of power of all digits of a number
$num=$num/10; // Calculate next number
}
if($sum==$i)
{
echo $i . "= Yes <br/>";
}
}
}
?>
Comments
Post a Comment