PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Armstrong Number

## Pages

Armstrong Number - phponwebsites.com
Showing posts with label Armstrong Number. Show all posts

# Find Armstrong Numbers between 1 to 1000 in PHP

This blog describes how to find Armstrong Numbers between 1 to 1000 using PHP?. Before we are going to program part, we should know what is Armstrong Number?. So only we can write program for find Armstrong Number in any languages like C, C++, PHP.

### what is Armstrong Number?

Armstrong Number is sum of 3 power of each digits equals to given number.
For example:
153 is Armstrong Number.
1^3 + 5^3 + 3 ^3
1 + 125 + 27
153

### PHP Program to find Armstrong Numbers:

Consider below example which is find Armstrong Numbers between 1 to 1000.

<?php
for(\$i = 1; \$i <= 1000; \$i++) {
\$sum = 0;
\$qu = \$i;
while(\$qu != 0) {
\$remainder = \$qu % 10;
\$thrice = \$remainder * \$remainder * \$remainder;
\$sum += \$thrice;
\$qu = \$qu / 10;
}
if (\$sum == \$i) {
echo "<p>\$i is armstrong number</p>";
}
}
?>

Now you got Armstrong Numbers between 1 to 1000.

Related Post: