Currency Denomination
In this program, we calculate the minimum number of currency notes required to make a given amount. The denominations used are 2000, 500, 200, 100, 50, 20, 10, 5, 2, and 1. The program takes an amount as input and determines how many of each denomination are needed to reach that amount.
Code Breakdown
Algorithm
-
Step Start: Initialize the Array of Denominations
- Define an array
notes[]
with the currency denominations in descending order.
- Define an array
-
Input the Amount:
- Prompt the user to enter the amount to be converted into currency denominations.
-
Process Each Denomination:
- For each denomination in
notes[]
:- Check if the Denomination is Usable:
- Determine if the current denomination can be used by checking if
amt / notes[i]
is greater than 0.
- Determine if the current denomination can be used by checking if
- Print the Number of Notes:
- Display how many notes of this denomination are needed.
- Update the Remaining Amount:
- Calculate the new amount by taking the remainder (
amt % notes[i]
).
- Calculate the new amount by taking the remainder (
- Check if the Denomination is Usable:
- For each denomination in
-
Repeat: Continue the process until the amount is reduced to 0.
-
Step End: Finish the process when the entire amount has been broken down into denominations and displayed.
Code Explanation
Example Flowchart
Start
|
V
Enter an amount (amt)
|
V
Initialize currency denominations (notes[])
|
V
Is amt > 0?
/ \
/ \
Yes \
| \
V \
Is amt >= notes[i]? V
/ \ End
/ \
Yes No
| |
V V
Print notes[i] End
x amt/notes[i]
|
V
Update amt to
amt % notes[i]
|
V
Increment i to i+1
|
V
Loop back to
Is amt > 0?