- 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

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.

#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); }

Minimum number of coins required: 7

- Related Questions & Answers
- C/C++ Program for Greedy Algorithm to find Minimum number of Coins
- Program to find minimum number of steps required to catch the opponent in C++
- Problem to Find Out the Maximum Number of Coins that Can be Collected in Python
- Program to find minimum number of pins required to hang all banners in C++
- Find minimum number of currency notes and values that sum to given amount in C++
- How to find the minimum number of jumps required to reach the end of the array using C#?
- Program to Find Out the Amount of Rain to be Caught between the Valleys in C++
- Minimum number of mails required to distribute all the questions using C++.
- Minimum number of coins that make a given value
- Minimum number of bottles required to fill K glasses in C++
- Minimum number of swaps required to sort an array in C++
- Find minimum steps required to reach the end of a matrix in C++
- Program to Find Out the Minimum Parsing Tree in C++
- 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

Advertisements