PHP program to check for an Armstrong number
Defination:-
In number theory, an armstrong number in a given number base b is a number that is the sum of its own digits each raised to the power of the number of digits. ... If the number obtained equals the original number then, we call that armstrong number.
in this program i'm going to show you how to find armstrong number
code:-
<?php
$n=153;
$sum=0;
$i=$n;
while($i!=0)
{
$x=$i%10;
$sum=$sum+$x*$x*$x;
$i=$i/10;
}
if($n==$sum)
{
echo "$n is an Armstrong Number.";
}
else
{
echo "$n is not an Armstrong Number.";
}
?>
output:-
153 is an Armstrong Number.
Post a Comment
If you have any doubts, Please let me know
Thanks!