20. Write a C program to count total number of notes in given amount.
Solution :-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int amount;
int note2000,note500,note200,note100,note50,note20,note10,note5,note2,note1;
note2000=note500=note200=note100=note50=note20=note10=note5=note2=note1=0;
printf("Enter the amount :-");
scanf("%d",&amount);
if(amount>=2000)
{
note2000 = amount/2000;
amount = amount -note2000*2000;
}
if(amount >= 500)
{
note500 = amount/500;
amount = amount - note500*500;
}
if(amount >= 200)
{
note200 = amount/200;
amount = amount - note200*200;
}
if(amount >= 100)
{
note100 = amount/100;
amount = amount - note100*100;
}
if(amount >= 50)
{
note50 = amount/50;
amount = amount - note50*50;
}
if(amount >= 20)
{
note20 = amount/20;
amount = amount - note20*20;
}
if(amount >= 10)
{
note10 = amount/10;
amount = amount - note10*10;
}
if(amount >= 5)
{
note5 = amount/5;
amount = amount - note5*5;
}
if(amount >= 2)
{
note2 = amount/2;
amount = amount - note2*2;
}
if(amount >= 1)
{
note1 = amount;
}
else
{
printf("Not proper");
}
printf("\n2000 :- %d",note2000);
printf("\n500 :- %d",note500);
printf("\n200 :- %d",note200);
printf("\n100 :- %d",note100);
printf("\n50 :- %d",note50);
printf("\n20 :- %d",note20);
printf("\n10 :- %d",note10);
printf("\n5 :- %d",note5);
printf("\n2 :- %d",note1);
printf("\n1 :- %d",note1);
getch();
}
Output :-