Write a function named change that has an integer parameter
Write a function named change () that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function.
Solution
Hello Student,
Pleas find the source Code :- http://pastebin.com/1xwV7RpB
Approach :-
As in this case all numbers are multiples of 5 except 1, So you can do the following.
Start checking from highest to lowest references . If reference parameter is lesser than the value of the , find how many multiples of this reference parameter you can use, and then do the same for remaining values.
e.g. 245 -> 100 is lesser than 245. Now we find that 2 multiples of 100 are lesser than 245. Now remaining value is 45, we go with 50, but 50 is greater, next is 20, again 2 20\'s can satisfy this. Now remaining is 5 , Now we need 1 5.
so 245 -> 2*100 + 2*20 + 1*5
