C++ program to check the coins forms x amount of rupees or not


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: 03-Mar-2022

99 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements