Php Program to Identify Armstrong Number



First, write a Code for inputting numbers for identifying armstrong numbers.
153=1*1*1+5*5*5+3*3*3=153.

(Armstrong.html)

<html>
<form method="POST" action="arm.php">
Enter Number:<input type="number" name="n1"><br>
<input type="submit" value="submit">
</form>
</html>



After inputting embed the PHP code into the form tag
(arm.php)

<?php
$arm=0;
$n=$_POST["n1"];
$og=$n;
while($n!=0) {
$rem=$n%10;
$arm=($rem*$rem*$rem)+$arm;
$n=$n/10;
}
if($og==$arm) {
echo " $og is Armstrong number";
}
else {
echo " $og is not Armstrong number";
}
?>









Comments