Algorithm to solve minimal number of coins problem.

The problem is: What is the minimal number of coins needed to make a change?

For given coin nominals

500, 200, 100, 50, 20, 10, 5, 2, 1, 0.50, 0.25, 0.1, 0.05, 0.01

What coins (or banknotes) will be given as a change for 254.78?

To solve this we need to check how many coins or banknotes of each nominal beginning from highest to lowest can be “fitted” for each part of the value.

The answer is:

200.0 50.0 2.0 2.0 0.5 0.25 0.01 0.01 0.01


1. Store initial money amount in variable M.
2. Place money nominals from highest to lowest in an array A. Create index to this array and name it I - it should be zero in the beginning.
3. Check if M < A[I]. If it is true increase I by one. If not subtract A[I] from M.
4. Check if M >= 0.01 <- or if it is bigger than smallest coin in array A <- last element of that array. If so go to step 3. 


Minimum Number Of Coins Algorithm
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. You can read more about it the Cookies&Privacy Policy Section Above. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this. You can read more about it the Cookies&Privacy Policy Section.