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

Leave a Reply

Related Posts: You may like

Write a program find Factorial of a number

Write a PHP program to Print table of Number

Write a PHP program to print prime number

Write a PHP program to print number is Even or Odd

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

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.