Check If Coins Form X Amount of Rupees in C++



Suppose we have two numbers K and X. Consider Amal has K, 500 rupee notes. We have to check whether the sums up to X rupees or not.

So, if the input is like K = 2; X = 900, then the output will be True, because 2*500 = 1000 and it is not less than 900.

Steps

To solve this, we will follow these steps −

if (500 * k) >= x, then:
   return true
Otherwise
   return false

Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;

bool solve(int k, int x){
   if ((500 * k) >= x){
      return true;
   } else{
      return false;
   }
}
int main(){
   int K = 2;
   int X = 900;
   cout << solve(K, X) << endl;
}

Input

2, 900

Output

1
Updated on: 2022-03-03T07:11:53+05:30

146 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements