Check if given coins can be used to pay a value of S | C ++ implementation to check if it is possible to pay a value ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void knowPair ( int a , int b , int n , int s , int m ) { int i = 0 , rem = 0 ; int count_b = 0 , flag = 0 ; while ( i <= a ) { rem = s - ( n * i ) ; count_b = rem / m ; if ( rem % m == 0 && count_b <= b ) { flag = 1 ; } i ++ ; } if ( flag == 1 ) { cout << " YES " << endl ; } else { cout << " NO " << endl ; } } int main ( ) { int A = 1 ; int B = 2 ; int n = 3 ; int S = 4 ; int m = 2 ; knowPair ( A , B , n , S , m ) ; return 0 ; }