Thursday, November 18, 2010

Roman number converter

for rm = 1 to 3000
print rm+" = ";
n=rm
for t = 1 to 3
if n-1000>=0 then
n=n-1000
print "M";
end if
next t
if n-900>=0 then
n=n-900
print "CM";
end if
if n-500>=0 then
n=n-500
print "D";
end if
if n-400>=0 then
n=n-400
print "CD";
end if
for f = 1 to 3
if n-100>=0 then
n=n-100
print "C";
end if
next f
if n-90>=0 then
n=n-90
print "XC";
end if
if n-50>=0 then
n=n-50
print "L";
end if
if n-40>=0 then
n=n-40
print "XL";
end if
for h = 1 to 3
if n-10>=0 then
n=n-10
print "X";
end if
next h
if n-9>=0 then
n=n-9
print "IX";
end if
if n-5>=0 then
n=n-5
print "V";
end if
if n-4>=0 then
n=n-4
print "IV";
end if
for k = 1 to 3
if n-1>=0 then
n=n-1
print "I";
end if
next k
print
next rm

No comments:

Post a Comment