Nth term where K + 1 th term is product of Kth term with difference of max and min digit of Kth term | C ++ implementation to find the value of the given function for the value ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MIN ( int n ) { int ans = 11 ; while ( n ) { ans = min ( ans , n % 10 ) ; n /= 10 ; } return ans ; } int MAX ( int n ) { int ans = -1 ; while ( n ) { ans = max ( ans , n % 10 ) ; n /= 10 ; } return ans ; } void Find_value ( int n , int k ) { k -- ; int x = 0 ; int y = 0 ; while ( k -- ) { x = MIN ( n ) ; y = MAX ( n ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } cout << n ; } int main ( ) { int N = 487 , D = 5 ; Find_value ( N , D ) ; return 0 ; }