Home » PHP Armstrong Number Program

PHP Armstrong Number Program

by Online Tutorials Library

Armstrong Number

An Armstrong number is the one whose value is equal to the sum of the cubes of its digits.

0, 1, 153, 371, 407, 471, etc are Armstrong numbers.

For example,

Logic:

  • Take the number.
  • Store it in a variable.
  • Take a variable for sum.
  • Divide the number with 10 until quotient is 0.
  • Cube the remainder.
  • Compare sum variable and number variable.

Armstrong number in PHP

Below program checks whether 407 is Armstrong or not.

Example:

Output:

PHP Armstrong number 1

Look at the above snapshot, the output displays that 407 is an Armstrong number.


Armstrong number using Form in PHP

A number is Armstrong or can also be checked using a form.

Example:

Output:

On entering the number 371, we got the following output.

PHP Armstrong number 2

On entering the number 9999, we got the following output.

PHP Armstrong number 3

Next TopicPalindrome Number

You may also like