Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

exchange problems to 0.xyz (after the dot)

조회 수: 1 (최근 30일)
yonatan friedman
yonatan friedman 2019년 12월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
making change problem
I need to exchange my money to "little-money" in this form :
[0.5 , 0.25 , 0.1 , 0.05 , 0.01]
I have : 0.68
the out put is : [1 , 0 , 1 , 1 , 3] %(0.5x1 + 0.25x0 + 0.1x1 + 0.05x1 + 3x0.01 = 0.68)
----------------------------------------
other example :
the input is 0.99
the out put is : [1 , 1 , 2 , 0 , 4] %(0.5x1 + 0.25x1 + 0.1x2 + 0.05x0 + 0.01x4 = 0.99)
--------------------------------

답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 21일
coinvals = [0.5 , 0.25 , 0.1 , 0.05 , 0.01];
numcoins = [1 , 0 , 1 , 1 , 3];
total_value = coinvals * numcoins(:);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by