take ourstarting number, for example368.
1)divide 368 by100.368/100= 3.68,
we take only an integer - 3,
this means that the bills would consist of 3 - $100 bills,
thensubtract from 368 our 3 - $100 bills.368-300= 68.
2) divide 68 by50.68/50= 1.36,
we takeonly an integer - 1,
this means that the bills would consist of 1 - $50 bills,
thensubtract from 68 our 1 - $50 bills.68-50= 18.
3) divide 18 by20. 18/20= 0.9,
we have a number less then zero,
this means that the bills would not consist a $50 bills,
and we move on...
4) divide 18 by 10. 18/10 = 1.8,
we take only an integer - 1,
this means that the bills would consist of 1 - $10 bills,
then subtract from 18 our 1 - $10 bills. 18-10 = 8.
5) divide 8 by 5. 8/5 = 1.6,
we take only an integer - 1,
this means that the bills would consist of 1 - $5 bills,
then subtract from 8 our 1 - $5 bills. 8-5 = 3.
6) divide 3 by 2. 3/2 = 1.5,
we take only an integer - 1,
this means that the bills would consist of 1 - $2 bills,
then subtract from 3 our 1 - $2 bills. 3-2 = 1.
7) divide 1 by 1. 1/1 = 1,
we have an integer - 1,
this means that the bills would consist of 1 - $1 bills,
and this means that the algorithm is finished!
Comments
Leave a comment