Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | C ++ program for the above approach . ; Function to find integer ; because 1 st integer is K itself ; Initialize min_d and max_d ; updating min_d and max_d ; break if min digit is 0 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int find ( int K , int N ) { N -- ; while ( N -- ) { int curr_term = K ; int min_d = 9 ; int max_d = 0 ; while ( curr_term > 0 ) { int r = curr_term % 10 ; min_d = min ( min_d , r ) ; max_d = max ( max_d , r ) ; curr_term = curr_term / 10 ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } int main ( ) { int K = 487 ; int N = 2 ; cout << find ( K , N ) << endl ; return 0 ; }