programming-examples/php/Basics/PHP program to find whether a number is Armstrong or not.php
2019-11-18 14:44:36 +01:00

26 lines
772 B
PHP

// If the sum of cubes of individual digits of a number is equal to the number itslef then it is called Armstrong Number.
<?php
if(isset($_POST['number']) && $_POST['number']!='')
{
$number = $_POST[ 'number' ]; // get the number entered by user
$temp = $number;
$sum = 0;
while($temp != 0 )
{
$remainder = $temp % 10; //find reminder
$sum = $sum + ( $remainder * $remainder * $remainder );
$temp = $temp / 10;
}
if( $number == $sum )
{
echo "$number is an Armstrong Number";
}else
{
echo "$number is not an Armstrong Number";
}
}
?>