Number formed by adding product of its max and min digit K times | Function that returns the product of maximum and minimum digit of N number . ; Finds the last digit . ; Moves to next digit ; Function to find the formed number ; K -- ; M ( 1 ) = N ; Check if minimum digit is 0 ; Driver Code
function prod_of_max_min ( n ) { var largest = 0 ; var smallest = 10 ; while ( n ) { var r = n % 10 ; largest = Math . max ( r , largest ) ; smallest = Math . min ( r , smallest ) ; n = parseInt ( n / 10 ) ; } return largest * smallest ; } function formed_no ( N , K ) { if ( K == 1 ) { return N ; } var answer = N ; while ( K -- ) { var a_current = prod_of_max_min ( answer ) ; if ( a_current == 0 ) break ; answer += a_current ; } return answer ; } var N = 487 , K = 100000000 ; document . write ( formed_no ( N , K ) + " " ) ;