// Способ первый
function IntToRoman( num: Cardinal ): string;
const
N = 13;
vals: array [1..N] of word =
( 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 );
roms: array [1..N] of string[2] =
( 'I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M' );
var
b: 1..N;
begin
Result := '';
b := N;
while num > 0 do
begin
while vals[b] > num do
Dec( b );
Dec( num, vals[b] );
Result := Result + roms[b];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage( IntToRoman( 1561 ) );
end;
// Способ второй
function IntToRoman( num: Cardinal ): string;
const
N = 13;
vals: array [1..N] of word =
( 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 );
roms: array [1..N] of string[2] =
( 'I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M' );
var
b: 1..N;
begin
Result := '';
b := N;
while ( num > 0 ) and ( b >= 1 ) do
begin
if num >= vals[b] then
begin
Result := Result + roms[b];
Dec( num, vals[b] );
end
else
Dec( b );
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage( IntToRoman( 1561 ) );
end;