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
function getProduct ( n ) { var product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return product ; } function productinRange ( l , r ) { if ( r - l > 9 ) return 0 ; else { var p = 1 ; for ( var i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } var l = 11 , r = 15 ; document . write ( productinRange ( l , r ) + " " ) ; l = 1 , r = 15 ; document . write ( productinRange ( l , r ) ) ;