Coding Challenge 1 : Find the Rupee Denominations
In India the currency is made up of Rupee denominations Re.1, Rs.2, Rs.5, Rs.10, Rs.20, Rs.50, Rs.100, Rs.200, Rs. 500 and Rs.2000. shopkeeper is trying to find the number of notes of each denomination that the shopkeeper can give a customer for a certain amount of money, such that he has to handle minimum number of notes. Write a program to list out the number of notes of each denomination for an amount received through the keyboard.
Solution 1 :
#include <iostream> using namespace std; int main() { int amount,notes; cout<<"Enter amount :- " cin>>amount; if(amount>=2000){ notes=amount/2000; cout<<"2000 *"<<notes<<"="<<2000*notes<<endl; amount=amount-(2000*notes); } if(amount>=500){ notes=amount/500; cout<<"500 *"<<notes<<"="<<500*notes<<endl; amount=amount-(500*notes); } if(amount>=200){ notes=amount/200; cout<<"200 *"<<notes<<"="<<200*notes<<endl; amount=amount-(200*notes); } if(amount>=100){ notes=amount/100; cout<<"100 *"<<notes<<"="<<100*notes<<endl; amount=amount-(100*notes); } if(amount>=50){ notes=amount/50; cout<<"50 *"<<notes<<"="<<50*notes<<endl; amount=amount-(50*notes); } if(amount>=20){ notes=amount/20; cout<<"20 *"<<notes<<"="<<20*notes<<endl; amount=amount-(20*notes); } if(amount>=10){ notes=amount/10; cout<<"10 *"<<notes<<"="<<10*notes<<endl; amount=amount-(10*notes); } if(amount>=5){ notes=amount/5; cout<<"5 *"<<notes<<"="<<5*notes<<endl; amount=amount-(5*notes); } if(amount>=2){ notes=amount/2; cout<<"2 *"<<notes<<"="<<2*notes<<endl; amount=amount-(2*notes); } if(amount>0){ notes=amount/1; cout<<"1 *"<<notes<<"="<<1*notes<<endl; amount=amount-(1*notes); } return 0; }
Solution 2 :
#include <iostream> using namespace std; int main() { int rupeesList[]={2000,500,200,100,50,20,10,5,2,1}; int amount,notes,i; cout<<"Enter the amount : "; cin>>amount; for(i=1;i<=9;i++) { if(amount>=rupeesList[i]) { notes=amount/rupeesList[i]; cout<<rupeesList[i]<<"*"<<notes<<"="<<rupeesList[i]*notes<<endl; amount=amount-(rupeesList[i]*notes); } } return 0; }
Solution 3:
#include <iostream> using namespace std; int main() { int rupeesList[]={1,2,5,10,20,50,100,200,500,2000}; int amount,notes,i; cout<<"Enter the amount :- "; cin>>amount; for(i=9;i>=0;i--) { if(amount>=rupeesList[i]) { notes=amount/rupeesList[i]; cout<<rupeesList[i]<<"*"<<notes<<"="<<rupeesList[i]*notes<<endl; amount=amount-(rupeesList[i]*notes);//Instead of using this statement, you can also use amount=amount%rupeesList[i]; } } return 0; }