+ 3

How do you this in code? (Exchang money by using 10$ , 5$, 2$ and 1$, Input = 13, Ex: 13$ = 10$ + 2$ +1$)

30th Sep 2018, 7:29 AM
Kittyky.n
Kittyky.n - avatar
6 Answers
+ 4
You have to divide you money for largest "piece" (10,5,2,1) for get the number of nth piece... After, you have to subtract number of nth piece from total money and repeat all starting with remaining money and next largest piece. Ex: 13 / 10= 1 ==> 13-(10*1)= 3 3/5 = 0 ==> 3-(5*0)=3 3/2= 1 ==> 3-(2*1)= 1 1/1= 1 ==> 1-(1*1)= 0
30th Sep 2018, 8:14 AM
KrOW
KrOW - avatar
+ 4
Ketan Lalcheta Yes, i know that but i think for understanding purpose is better use subtraction method
30th Sep 2018, 8:25 AM
KrOW
KrOW - avatar
+ 3
KrOW to get output of remianing balance after division, you can use % operator... 13%10 = 3 and so on... substract method also work fine whatever you have mentioned
30th Sep 2018, 8:18 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
i made this a while back. With a few small changes it should be what you are looking for. https://code.sololearn.com/cwFDDBLW9764/?ref=app
30th Sep 2018, 7:48 AM
davy hermans
davy hermans - avatar
+ 2
Thank you all for your help!✌
1st Oct 2018, 4:47 AM
Kittyky.n
Kittyky.n - avatar