Check if N can be represented as sum of positive integers containing digit D at least once | Function to check if N contains digit D in it ; Iterate until N is positive ; Find the last digit ; If the last digit is the same as digit D ; Return false ; Function to check if the value of N can be represented as sum of letegers having digit d in it ; Iterate until N is positive ; Check if N contains digit D or not ; Subtracting D from N ; Return false ; Driver Code
function findDigit ( N , D ) { while ( N > 0 ) { let a = N % 10 ; if ( a == D ) { return true ; } N = Math . floor ( N / 10 ) ; } return false ; } function check ( N , D ) { while ( N > 0 ) { if ( findDigit ( N , D ) == true ) { return true ; } N -= D ; } return false ; } let N = 24 ; let D = 7 ; if ( check ( N , D ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }