Program to find out a minimum number of notes and coins of various denominations needed for given amount.
#include<iostream.h>
#include<conio.h>
void main()
{
int amount, note2000, note500, note100, note50, note20, note10, coin5, coin2, coin1;
note2000=note500=note100=note50=note20=note10=coin5=coin2=coin1=0;
cout<<"Enter the amount :";
cin>>amount;
if(amount>=2000)
{
note2000=amount/2000;
amount%=2000;
}
if(amount>=500)
{
note500=amount/500;
amount%=500;
}
if(amount>=100)
{
note100=amount/100;
amount%=100;
}
if(amount>=50)
{
note50=amount/50;
amount%=50;
}
if(amount>=20)
{
note20=amount/20;
amount%=20;
}
if(amount>=10)
{
note10=amount/10;
amount%=10;
}
//Remove the coin section if only notes is needed
if(amount>=5)
{
coin5=amount/5;
amount%=5;
}
if(amount>=2)
{
coin2=amount/2;
amount%=2;
}
if(amount>=1)
{
coin5=amount/1;
amount%=1;
}
cout<<"\n\nMinimum No. of notes requeired for "<<amount<<" is : "<<endl;
cout<<"\nNo. of Rs 2000 Note : "<<note2000;
cout<<"\nNo. of Rs 500 Note : "<<note500;
cout<<"\nNo. of Rs 100 Note : "<<note100;
cout<<"\nNo. of Rs 50 Note : "<<note50;
cout<<"\nNo. of Rs 20 Note : "<<note20;
cout<<"\nNo. of Rs 10 Note : "<<note10;
//Remove the following 3 statements if only notes is needed
cout<<"\nNo. of Rs 5 coin : "<<coin5;
cout<<"\nNo. of Rs 2 Coin : "<<coin2;
cout<<"\nNo. of Rs 1 Coin : "<<coin1;
cout<<"\nTotal No. of Notes : "<<(note2000+note500+note100+note50+note20+note10);
cout<<"\nTotal No. of Coins : "<<(coin5+coin2+coin1);
getch();
}
No comments:
Post a Comment