function C = RomanNum()
% C is a 3999-by-1 cell array where RN{k} is a string that specifies
% the Roman Numeral having value k.

for a = 0:3
for b = 0:9
for c = 0:9
for d = 0:9
% Here is the integer to convert...
n = a*1000 + b*100 + c*10 + d;
if n>0
% Concatenate the right set oif numerals..
C{n} = [Thou2R(a) Hund2R(b) Tens2R(c) Ones2R(d)];
end
end
end
end
end

function r = Ones2R(x)
% x is an integer that satisfies 0<=x<=9
% r is the roman numeral with value x
Ones = {'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'};
if x==0
r = '';
else
r = Ones{x};
end

function r = Tens2R(x)
% x is an integer that satisfies 0<=x<=9
% r is the roman numeral with value 10*x
Tens = {'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'};
if x==0
r = '';
else
r = Tens{x};
end

function r = Hund2R(x)
% x is an integer that satisfies 0<=x<=9
% r is the roman numeral with value 100*x
Hundreds = {'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'};
if x==0
r = '';
else
r = Hundreds{x};
end

function r = Thou2R(x)
% d is an integer that satisfies 0<=x<=3
% r is the roman numeral with value 1000*x
Thousands = {'M','MM','MMM'};
if x==0
r = '';
else
r = Thousands{x};
end