Nth term where K + 1 th term is product of Kth term with difference of max and min digit of Kth term | Function to find minimum digit in the decimal representation of N ; Loop to find the minimum digit in the number ; Function to find maximum digit in the decimal representation of N ; Loop to find the maximum digit in the number ; Function to find the value of the given function ; Loop to compute the values of the given number ; Driver Code ; Function Call
function MIN ( n ) { let ans = 11 ; while ( n ) { ans = parseInt ( Math . min ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function MAX ( n ) { let ans = - 1 ; while ( n ) { ans = parseInt ( Math . max ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function Find_value ( n , k ) { k -- ; let x = 0 ; let y = 0 ; while ( k -- ) { x = parseInt ( MIN ( n ) ) ; y = parseInt ( MAX ( n ) ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } document . write ( n ) ; } let N = 487 , D = 5 ; Find_value ( N , D ) ;