An armstrong number is a number that is equal to the sum of cubes of its digits.
For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
Let’s see the approach ,how to find given number is armstrong or not ?
<?php
$num = 407; // user input
$sum =0;
$temp = $num;
while($temp !=0)
{
$rem = $temp % 10;
$sum = $sum+$rem*$rem*$rem;
$temp = $temp/10;
}
if($num == $sum)
{
echo $num." is armstrong";
}
else{
echo $num." is not a armstrong";
}
Output:
407 is armstrong