In: Statistics and Probability
using math lab, Write a code to compute the change in dollars (no cents) to be given back to a restaurant patron who pays the bill in cash. That is, find and enumerate the various combinations (of common currency notes only) that can amount to the change due.
ANSWER::
Here is the solution to your question. I tried my
best to solve your doubt, however, if you find it is not as good as
expected by you. Please do write your further doubts regarding this
question in the comment section, I will try to resolve your doubts
regarding the submitted solution as soon as possible.
If you think, the solution provided by me is helpful to you please
do an upvote.
S=[1,2,5,10,20,50,100,500,1000]; % common notes in dollor m=size(S,2)+1; n=input("Enter the amount: "); sol=combination(S,m,n); fprintf("Number of combination of notes for the change of %d is, %d\n",n,sol); |
function ans=combination(S,m,n) if n==0 ans=1; return endif if n<0 ans=0; return endif if m<=1 && n>=1 ans=0; return endif ans= combination(S,m-1,n)+combination(S,m,n-S(m-1)); return endfunction |
NOTE:: I HOPE YOUR HAPPY WITH MY ANSWER....***PLEASE SUPPORT ME WITH YOUR RATING...
***PLEASE GIVE ME "LIKE"...ITS VERY IMPORTANT FOR ME NOW....PLEASE SUPPORT ME ....THANK YOU