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
< ? php function findArmstrong ( $ low , $ high ) { for ( $ i = $ low + 1 ; $ i < $ high ; ++ $ i ) { $ x = $ i ; $ n = 0 ; while ( $ x != 0 ) { $ x = ( int ) ( $ x / 10 ) ; ++ $ n ; } $ pow_sum = 0 ; $ x = $ i ; while ( $ x != 0 ) { $ digit = $ x % 10 ; $ pow_sum += ( int ) ( pow ( $ digit , $ n ) ) ; $ x = ( int ) ( $ x / 10 ) ; } if ( $ pow_sum == $ i ) echo $ i . " " ; } } $ num1 = 100 ; $ num2 = 400 ; findArmstrong ( $ num1 , $ num2 ) ; ? >