Check if given coins can be used to pay a value of S | Function to check if it is possible to pay a value ; Loop to add the value of coin A ; Condition to check if it is possible to pay a value of S ; Driver Code
function knowPair ( a , b , n , s , m ) { var i = 0 , rem = 0 ; var count_b = 0 , flag = 0 ; while ( i <= a ) { rem = s - ( n * i ) ; count_b = parseInt ( rem / m ) ; if ( rem % m == 0 && count_b <= b ) { flag = 1 ; } i ++ ; } if ( flag == 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var A = 1 ; var B = 2 ; var n = 3 ; var S = 4 ; var m = 2 ; knowPair ( A , B , n , S , m ) ;