Php Armstrong number
- Take the number.
- Store it in a variable.
- Take a variable for sum.
- Divide the number with 10 until quotient is 0.
- Cube the remainder.
- Compare sum variable and number variable.
Armstrong number in PHP
null
Below program checks whether 407 is Armstrong or not.
Example:
- <?php
- $num=407;
- $total=0;
- $x=$num;
- while($x!=0)
- {
- $rem=$x%10;
- $total=$total+$rem*$rem*$rem;
- $x=$x/10;
- }
- if($num==$total)
- {
- echo “Yes it is an Armstrong number”;
- }
- else
- {
- echo “No it is not an armstrong number”;
- }
- ?>
Output:
null

Look at the above snapshot, the output displays that 407 is an Armstrong number.