- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find out the minimum number of coins required to pay total amount in C++

Suppose we have a number N, and unlimited number of coins worth 1, 10 and 25 currency coins. Find minimum number of coins we need to use to pay exactly amount N. Suppose N is 14, then number of coins will be 5, as one 10 value coin and four 1 value coin.

To solve this, we have to use these steps −

- If N < 10, then return N number of 1 value coins
- If N > 9 and N < 25, then divide the value with 10, and get the result, the remaining will be covered using 1 value coin, add the count to get result
- If N > 25, then divide it with 25, take the result, when result is < 25, then again do the same task for the second point and so on.

## Example

#include<iostream> using namespace std; int countMinCoins(int n) { if(n<10) return n; else if(n > 9 && n < 25){ int count = n/10; count += n%10; return count; } else { int count = n/25; return count + countMinCoins(n%25); } } int main() { int n = 88; cout << "Minimum number of coins required: " << countMinCoins(n); }

## Output

Minimum number of coins required: 7

- Related Questions & Answers
- C++ code to find out the total amount of sales we made
- C++ Program to find out the minimum number of operations required to defeat an enemy
- C++ Program to find out the least amount of money required to subscribe to the OTT services
- C/C++ Program for Greedy Algorithm to find Minimum number of Coins
- Problem to Find Out the Maximum Number of Coins that Can be Collected in Python
- Program to find minimum number of steps required to catch the opponent in C++
- C++ Program to find out the total price
- Minimum number of coins that make a given value
- Program to find minimum number of operations required to make one number to another in Python
- Program to find number of coins needed to make the changes with given set of coins in Python
- Find the minimum number of preprocess moves required to make two strings equal in Python
- Program to find minimum number of hops required to reach end position in Python
- Program to find minimum number of buses required to reach final target in python
- Program to find minimum number of pins required to hang all banners in C++
- Program to find minimum number of flips required to have alternating values in Python

Advertisements