this slowpoke moves

Generate Roman Numbers

function DecToRoman ( iDecimal: longint ): string;
const  aRomans:
  array [ 1..13 ] of string = ( 'I', 'IV', 'V',   'IX', 'X', 'XL','L', 'XC',
                                'C', 'CD', 'D', 'CM', 'M' );
  aArabics: array [ 1..13 ]
  of integer = ( 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);
  var   i: integer;
begin
  for i := 13 downto 1 do
  while ( iDecimal >= aArabics [ i ] ) do
  begin
  iDecimal := iDecimal - aArabics [ i ];
  result := result + aRomans [ i ];
  end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit2.Text := DecToRoman(StrToInt(Edit1.Text));
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate