Armstrong number in PHP using for and while loop
This is Armstrong number logic
371 = 33+73+13
![]() |
Output |
PHP code: example
<?php
error_reporting(0); /* this is use for avoid minor warning in php */
?>
<form action="" method="post">
<input type="text" name="num"> /* put range that you to check armstrong series */gg
<input type="submit" name="sub" value="Submit">
</form>
<hr>
<?php
if($_POST['sub']=="Submit")
{
$num=$_POST['num']; /* ex: $num = 371 */
for($i=10; $i<$num; $i++)
{
$t=$i;
$t2=$i;
$sum=0;
while($t>0)
{
$rem=$t%10; /* $rem= 371 % 10 (result $rem=1)
$sum=$sum+(pow($rem,3)); $sum= 0+(pow(1,3))
$t=($t-$rem)/10; $t= (371- 1)/10 */
}
if($sum==$t2)
{
echo "armstrome serises are:";
echo"$t2<br>";
}
else
{
continue;
}
}
}
?>
armstrong numbers in php
Reviewed by 4khdimg
on
11:11 PM
Rating:
Reviewed by 4khdimg
on
11:11 PM
Rating:

No comments:
If you have any doubts. Please let me knew