Count numbers from a given range whose product of digits is K | Function to find the product of digits of a number ; Stores product of digits of N ; Update res ; Update N ; Function to count numbers in the range [ 0 , X ] whose product of digit is K ; Stores count of numbers in the range [ L , R ] whose product of digit is K ; Iterate over the range [ L , R ] ; If product of digits of i equal to K ; Update cnt ; Driver Code
function prodOfDigit ( N ) { let res = 1 ; while ( N ) { res = res * ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } return res ; } function cntNumRange ( L , R , K ) { let cnt = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( prodOfDigit ( i ) == K ) { cnt ++ ; } } return cnt ; } let L = 20 , R = 10000 , K = 14 ; document . write ( cntNumRange ( L , R , K ) ) ;