Find minimum number of coins that make a given value: Difference between revisions
Find minimum number of coins that make a given value (view source)
Revision as of 06:10, 21 April 2023
, 1 year agono edit summary
Drkameleon (talk | contribs) (added Arturo) |
No edit summary |
||
Line 345:
Igual que la entrada de FreeBASIC.
</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
const Coins: array [0..7] of integer = (1,2,5,10,20,50,100,200);
procedure MinimumCoins(Memo: TMemo; Value: integer);
var I,C: integer;
begin
Memo.Lines.Add('Providing Change for: '+IntToStr(Value));
for I:=High(Coins) downto 0 do
begin
C:=Value div Coins[I];
Value:=Value mod Coins[I];
Memo.Lines.Add(IntToStr(C)+' coins of '+IntToStr(Coins[I]));
end;
Memo.Lines.Add('');
end;
procedure TestMinimumCoins(Memo: TMemo);
begin
MinimumCoins(Memo,988);
MinimumCoins(Memo,1307);
MinimumCoins(Memo,37511);
MinimumCoins(Memo,0);
end;
</syntaxhighlight>
{{out}}
<pre>
Providing Change for: 988
4 coins of 200
1 coins of 100
1 coins of 50
1 coins of 20
1 coins of 10
1 coins of 5
1 coins of 2
1 coins of 1
Providing Change for: 1307
6 coins of 200
1 coins of 100
0 coins of 50
0 coins of 20
0 coins of 10
1 coins of 5
1 coins of 2
0 coins of 1
Providing Change for: 37511
187 coins of 200
1 coins of 100
0 coins of 50
0 coins of 20
1 coins of 10
0 coins of 5
0 coins of 2
1 coins of 1
Providing Change for: 0
0 coins of 200
0 coins of 100
0 coins of 50
0 coins of 20
0 coins of 10
0 coins of 5
0 coins of 2
0 coins of 1
</pre>
|