- Related Questions & Answers
- Finding least number of notes to sum an amount - JavaScript
- Count the number of currency notes needed in C++
- Find minimum sum of factors of number using C++.
- Find out the minimum number of coins required to pay total amount in C++
- Find smallest number with given number of digits and sum of digits in C++
- Minimum number of squares whose sum equals to given number n
- Minimum number with digits as and 7 only and given sum in C++
- Program to find the formatted amount of cents of given amount in Python
- C Program to Find the minimum sum of factors of a number?
- Minimum number of coins that make a given value
- Program to find tree level that has minimum sum in C++
- Find a number x such that sum of x and its digits is equal to given n in C++
- Find a number x such that sum of x and its digits is equal to given n using C++.
- Program to find number of subsequences that satisfy the given sum condition using Python
- Java Program to find minimum sum of factors of a number

- 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 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.

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

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

Advertisements