Print all numbers up to N having product of digits equal to K | Function to find the product of digits of a number ; Stores the product of digits of a number ; Return the product ; Function to prlet all numbers upto N having product of digits equal to K ; Stores whether any number satisfying the given conditions exists or not ; Iterate over the range [ 1 , N ] ; If product of digits of arr [ i ] is equal to K or not ; Prlet that number ; If no numbers are found ; Given value of N & K ; Function call to prlet all numbers from [ 1 , N ] with product of digits K
function productOfDigits ( N ) { let product = 1 ; while ( N != 0 ) { product = product * ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } return product ; } function productOfDigitsK ( N , K ) { let flag = 0 ; for ( let i = 1 ; i <= N ; ++ i ) { if ( K == productOfDigits ( i ) ) { document . write ( i + " " ) ; flag = 1 ; } } if ( flag == 0 ) document . write ( - 1 ) ; } let N = 500 , K = 10 ; productOfDigitsK ( N , K ) ;