Armstrong Numbers between two integers | Prints Armstrong Numbers in given range ; number of digits calculation ; compute sum of nth power of its digits ; checks if number i is equal to the sum of nth power of its digits ; Driver code
function findArmstrong ( low , high ) { for ( let i = low + 1 ; i < high ; ++ i ) { let x = i ; let n = 0 ; while ( x != 0 ) { x = parseInt ( x / 10 ) ; ++ n ; } let pow_sum = 0 ; x = i ; while ( x != 0 ) { let digit = x % 10 ; pow_sum += parseInt ( Math . pow ( digit , n ) ) ; x = parseInt ( x / 10 ) ; } if ( pow_sum == i ) document . write ( i + " " ) ; } } let num1 = 100 ; let num2 = 400 ; findArmstrong ( num1 , num2 ) ;