Info
この質問は閉じられています。 編集または回答するには再度開いてください。
exchange problems to 0.xyz (after the dot)
1 回表示 (過去 30 日間)
古いコメントを表示
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)
--------------------------------
0 件のコメント
回答 (1 件)
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(:);
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!