Print all Strong numbers less than or equal to N | Store the factorial of all the digits from [ 0 , 9 ] ; Function to return true if number is strong or not ; Converting N to String so that can easily access all it 's digit ; sum will store summation of factorial of all digits of a number N ; Returns true of N is strong number ; Function to print all strong number till N ; Iterating from 1 to N ; Checking if a number is strong then print it ; Given number ; Function call
let factorial = [ 1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 ] ; function isStrong ( N ) { let num = N . toString ( ) ; let sum = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { sum += factorial [ num [ i ] - ' ' ] ; } return sum == N ; } function printStrongNumbers ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { if ( isStrong ( i ) ) { document . write ( i + " " ) ; } } } let N = 1000 ; printStrongNumbers ( N ) ;