Find Armstrong Number

An Armstrong number is sum of the cubes of its digits is equal to the number itself.

There are six Armstrong numbers in the range of 0 and 999.

Armstrong number 1: 0
Armstrong number 2: 1
Armstrong number 3: 153
Armstrong number 4: 370
Armstrong number 5: 371
Armstrong number 6: 407

PHP Program Logic for Armstrong Number:

1. First You have to take the number.
2. Than taken number store it in a another variable.
3. Take a variable for sum.
4. Divide the number with 10 until quotient is 0.
5. Cube the remainder.
6. Compare sum variable and number variable.

PHP program to find Armstrong number

<?php
$num = 407;
$total = 0;
$temp = $num;
while($temp!=0)
{
	$rem = $temp%10;
	$total = $total+$rem*$rem*$rem;
	$temp = $temp/10;
}
if($num == $total)
{
	echo "Yes it is an Armstrong number";
}
else
{
	echo "No it is not an armstrong number";
}
?>

PHP program to find Armstrong number using HTML Form

<form method="post">
 <input type="text" name="number" placeholder="Enter number" />
 <input type="submit" value="Submit" />
</form>
<?php
if(isset($_POST['number']))
{
	$num = $_POST['number'];
	$total = 0;
	$temp = $num;
	while($temp!=0)
	{
		$rem = $temp%10;
		$total = $total+$rem*$rem*$rem;
		$temp = $temp/10;
	}
	if($num == $total)
	{
		echo "Yes it is an Armstrong number";
	}
	else
	{
		echo "No it is not an armstrong number";
	}
}
?>

Program Keywords: armstrong numbers list, armstrong numbers between 1 to 999, armstrong number program, armstrong numbers between 1 to 500, armstrong number php, armstrong number in c++, armstrong number program in php, armstrong number algorithm, find armstrong number, print armstrong number

About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.