- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 minimum number of currency notes and values that sum to given amount in C++

Suppose we have such amount, and we have to find the minimum number of notes of different denominations, that sum up to the given amount. Start from highest denomination notes, try to find as many notes possible for given amount. Here the assumption is that we have infinite amount of {2000, 500, 200, 100, 50, 20, 10, 5, 2, 1}. So if the amount is say 800, then notes will be 500, 200, 100.

Here we will use the greedy approach to solve this problem.

## Example

#include<iostream> using namespace std; void countNotes(int amount) { int notes[10] = { 2000, 500, 200, 100, 50, 20, 10, 5, 2, 1 }; int noteFreq[10] = { 0 }; for (int i = 0; i < 10; i++) { if (amount >= notes[i]) { noteFreq[i] = amount / notes[i]; amount = amount - noteFreq[i] * notes[i]; } } cout << "Note count:" << endl; for (int i = 0; i < 9; i++) { if (noteFreq[i] != 0) { cout << notes[i] << " : " << noteFreq[i] << endl; } } } int main() { int amount = 1072; cout << "Total amount is: " << amount << endl; countNotes(amount); }

## Output

Total amount is: 1072 Note count: 500 : 2 50 : 1 20 : 1 2 : 1

- Related Articles
- Count the number of currency notes needed in C++
- Finding least number of notes to sum an amount - JavaScript
- A lady went to a bank with a cheque of Rs. 100000. She asked the cashier to give her Rs. 500 and Rs. 2000 currency notes in return. She got 125 currency notes in all. Find the number of each kind of currency notes.
- Find out the minimum number of coins required to pay total amount in C++
- Minimum number with digits as and 7 only and given sum in C++
- Find minimum sum of factors of number using C++.
- Minimum number of squares whose sum equals to given number n
- C Program to Find the minimum sum of factors of a number?
- Program to find tree level that has minimum sum in C++
- Find smallest number with given number of digits and sum of digits in C++
- Find a number x such that sum of x and its digits is equal to given n in C++
- Make a list of various uses of papers. Observe currency notes carefully. Do you find any difference between currency paper and the paper in your notebook? Find out where currency paper is made.
- Find the Largest number with given number of digits and sum of digits in C++
- Find a number x such that sum of x and its digits is equal to given n using C++.
- Add minimum number to an array so that the sum becomes even in C++?

Advertisements