Find if it is possible to get a ratio from given ranges of costs and quantities | C ++ program to find if it is possible to get the ratio r ; Returns true if it is possible to get ratio r from given cost and quantity ranges . ; Calculating cost corresponding to value of i ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isRatioPossible ( int lowCost , int upCost , int lowQuant , int upQuant , int r ) { for ( int i = lowQuant ; i <= upQuant ; i ++ ) { int ans = i * r ; if ( lowCost <= ans && ans <= upCost ) return true ; } return false ; } int main ( ) { int lowCost = 14 , upCost = 30 , lowQuant = 5 , upQuant = 12 , r = 9 ; if ( isRatioPossible ( lowCost , upCost , lowQuant , upQuant , r ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }