PHP Program to Find Armstrong Number



In this post I am going to describe the basic PHP Program which tell us weather the Number is Armstrong or not. Armstrong number are those number whose sum of the thrice multiplication of each digit by itself is that number eg for 407 we have 4*4*4+0*0*0+7*7*7=407. The result is 407 so 407 is Armstrong number.

<html>
	<head>
		<title>Armstrong Number</title>
	</head>
	<body>
		<form action="" method='POST'>
		<label for="number">Please Enter 3 digit Number</label>
		<input type="text" name="number" value="">
		<br><br>
		
		<input type="submit" value="Done" name="submit">
		</form>
	</body>
</html>

<?php
if(isset($_POST['submit']))
	{
		$number= $_POST['number'];
		$num=$number;
		$sum=0;
		for($i=0;$i<3;$i++)
		{
			$rem=$number%10;
			$number=$number/10;
			$sum=$sum+($rem*$rem*$rem);
		
		}
		if($sum==$num)
		{
			echo "The Number is Armstrong Number";
		}
		else
		{
			echo "The Number is NOT Armstrong Number";
		}
	}
?>

Program Output:

Stay tuned for the PHP Magento, WordPress and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.