What is Armstrong Number ?

An armstrong number is any number of n digits which is equal to the sum of nth power of digits in the number. Generally in most programming cases we consider numbers from 000 to 999 that is 3 digit numbers. Thus, we also define armstrong number is any number of 3 digits as sum of cubes of digits in number.

For Example:

3 Digit Armstrong Number 370
= (3*3*3)+(7*7*7)+(0*0*0)
= (27)+(343)+(0)
= 370

4 Digit Armstrong Number 8208
= (8*8*8*8)+(2*2*2*2)+(0*0*0*0)+(8*8*8*8)
= 4096+16+0+4096
= 8208

Write a Program to Check Armstrong Number. 

Program

<?php
$num=370;
$total=0; 
$x=$num; 
while($x!=0) { 
   $rem=$x%10; 
   $total=$total+$rem*$rem*$rem; 
   $x=$x/10; 
} 
if($num==$total) { 
   echo "Yes it is an Armstrong number"; 
} else { 
   echo "No it is not an armstrong number"; 
}
//List of ArmStrong Number You Try 0,1,153,370,371,407 
?>

Output: Yes it is an Armstrong number

Demo Link :

demo

 

(Visited 194 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *