Find minimum number of coins that make a given value: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 739:
2 x 1
1 x 1
 
A total of 11 coins in all.
</pre>
 
=={{header|XPL0}}==
{{trans|Wren}}
<lang XPL0>int Denom, Denoms, Coins, Amount, Remaining, I, N;
[Denoms:= [200, 100, 50, 20, 10, 5, 2, 1];
Coins:= 0;
Amount:= 988;
Remaining:= 988;
Text(0, "The minimum number of coins needed to make a value of ");
IntOut(0, Amount); Text(0, " is as follows:
");
Format(3, 0);
for I:= 0 to 7 do
[Denom:= Denoms(I);
N:= Remaining/Denom;
if N > 0 then
[Coins:= Coins + N;
RlOut(0, float(Denom)); Text(0, " x "); IntOut(0, N); CrLf(0);
Remaining:= rem(Remaining/Denom);
if Remaining = 0 then I:= 7;
];
];
Text(0, "
A total of "); IntOut(0, Coins); Text(0, " coins in all.
");
]</lang>
 
{{out}}
<pre>
The minimum number of coins needed to make a value of 988 is as follows:
200 x 4
100 x 1
50 x 1
20 x 1
10 x 1
5 x 1
2 x 1
1 x 1
 
A total of 11 coins in all.
772

edits