Cumulative product of digits of all numbers in the given range | Function to get product of digits ; Function to find the product of digits of all natural numbers in range L to R ; Iterate between L to R ; Driver Code
def getProduct ( n ) : NEW_LINE INDENT product = 1 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT product = product * ( n % 10 ) NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return product NEW_LINE DEDENT def productinRange ( l , r ) : NEW_LINE INDENT if ( r - l > 9 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT p = 1 NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT p = p * getProduct ( i ) NEW_LINE DEDENT return p NEW_LINE DEDENT DEDENT l = 11 NEW_LINE r = 15 NEW_LINE print ( productinRange ( l , r ) , end = ' ' ) NEW_LINE l = 1 NEW_LINE r = 15 NEW_LINE print ( productinRange ( l , r ) ) NEW_LINE