C Program to find the number of denominations for a given amount
Last updated on September 23, 2020
The following program asks the user to enter an amount and prints number of notes (of denominations 500, 100, 50, 20, 10, 1) to be distributed. For example, if the user enters $451, then 4 note of 100, 1 note of 50 and 1 note of 1 is required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /***************************************************************
Program to find the number of denominations for a given amount
***************************************************************/
#include <stdio.h>
#define SIZE 6
int main()
{
int amount, notes;
// currency denominations
int denominations[SIZE] = {500, 100, 50, 20, 10, 1};
printf("Enter amount: ");
scanf("%d", &amount);
printf("\n");
for (int i = 0; i < SIZE; i++)
{
notes = amount / denominations[i];
if (notes)
{
amount = amount % denominations[i]; // remaining money
printf("%d * %d = %d \n", notes, denominations[i],
notes * denominations[i]);
}
}
return 0;
}
|
Expected Output: 1st run:
1 2 3 4 5 6 | Enter amount: 642
1 * 500 = 500
1 * 100 = 100
2 * 20 = 40
2 * 1 = 2
|
2nd run:
1 2 3 4 5 6 | Enter amount: 9241
18 * 500 = 9000
2 * 100 = 200
2 * 20 = 40
1 * 1 = 1
|
Recommended Programs
- C Program to find Prime Numbers
- C Program to find LCM and HCF of two numbers
- C Program to find the student's grade
- C Program to find the sum of natural numbers upto N terms
- C Program to check whether a year is a leap year
Load Comments