Find the number of currency notes required

A cashier has currency notes of denominations 5, 10, 50, 100, 500 and 1000. If the amount to be withdrawn is input through the keyboard in multiple of 5, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
    long int amount;
	int thousand, five_hundred, hundred, fifty, ten, five;

	printf("Enter the amount to withdraw\t:");
	scanf("%ld",&amount);

	thousand = amount/1000;
	amount = amount%1000;
	five_hundred = (amount/100)/5;
	hundred = (amount/100)%5;
	amount = amount%100;
	fifty = (amount/10)/5;
	ten = (amount/10)%5;
	amount = amount%10;
	five = amount/5;

	printf("\nThousand     = %d",thousand);
	printf("\nFive Hundred = %d",five_hundred);
	printf("\nHundred      = %d",hundred);
	printf("\nFifty        = %d",fifty);
	printf("\nTen          = %d",ten);
	printf("\nFive         = %d",five);

	getch();
}

Output

Enter the amount to withdraw    :45875

Thousand     = 45
Five Hundred = 1
Hundred      = 3
Fifty        = 1
Ten          = 2
Five         = 1

Explanation

Let us understand the above program with the help of an example.

Let the amount to be withdrawn be 45875
Mathematically we all know that 45875 will comprise of,
45 notes of thousand rupees,
1 note of 500,
3 notes of 100,
1 note of 50,
2 notes of 10 and
1 note of 5
Now, let us understand how to implement this in a program.

thousand = amount/1000;
Using the above statement, number of notes of thousand rupees is calculated.
In above example, thousand = 45875 / 1000 = 45

Now, we have to extract the remaining amount, which is done using the expression
amount = amount%1000;
In above example, amount = 45875 % 1000 = 875

To calculate the number of notes of 500, following statement is used:
five_hundred = (amount/100)/5;
In above example, five_hundred = (875 / 100) / 5 = 8 / 5 = 1
If the value of amount be 375 then, five_hundred = (375 / 100) / 5 = 3 / 5 = 0

To calculate the number of notes of 100, following statement is used:
hundred = (amount/100)%5;
In above example, hundred = (875 / 100) % 5 = 8 % 5 = 3
If the value of amount be 575 then, hundred = (575 / 100) % 5 = 5 % 5 = 0

Now, we have to extract the remaining amount, which is done using the expression
amount = amount%100;
In above example, amount = 875 % 100 = 75

To calculate the number of notes of 50, following statement is used:
fifty = (amount/10)/5;
In above example, fifty = (75 / 10) / 5 = 7 / 5 = 1
If the value of amount be 55 then, fifty = (45 / 10) / 5 = 4 / 5 = 0

To calculate the number of notes of 10, following statement is used:
ten = (amount/10)%5;
In above example, ten = (75 / 10) % 5 = 7 % 5 = 2
If the value of amount be 55 then, ten = (55 / 10) % 5 = 5 % 5 = 0

Now, we have to extract the remaining amount, which is done using the expression
amount = amount%10;
In the above example, amount = 75 % 10 = 5

Finally, the number of notes of 5 are calculated using the bellow expression:
five = amount/5;
In the above example, five = 5 / 5 = 1