As of October, 2016, Embarcadero is offering a free release
of Delphi (Delphi
10.1 Berlin Starter Edition ). There
are a few restrictions, but it is a welcome step toward making
more programmers aware of the joys of Delphi. They do say
"Offer may be withdrawn at any time", so don't delay if you want
to check it out. Please use the
link to let me know if the link stops working.
Support DFF - Shop
If you shop at Amazon anyway, consider
using this link.
We receive a few cents from each
Support DFF - Donate
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.
For over 15 years
Mensa Page-A-Day calendars have provided several puzzles a year
for my programming pleasure. Coding "solvers" is most fun,
but many programs also allow user solving, convenient for "fill
in the blanks" type. Below are Amazon links to the
two most recent years.
365 Puzzlers Calendar 2017
365 Puzzlers Calendar 2018
(Hint: If you can
wait, current year calendars are usually on sale in January.)
e-mail with your comments about this program (or anything else).
Write a program to convert Arabic numbers less
than 4000 to Roman numeral notation and display the result.
Background & Techniques
A good chance to review your Roman
numeral knowledge. A quick Web search will turn up lots of good links to
After playing with a few numbers I noticed that
the digits 1 through 9 have the same pattern whether they are in the
unit's, ten's, hundred's or thousand's position ( thousands up to MMM). The actual
characters are different but the pattern is the same.
If we make a table
containing the seven characters I, V, X, L, C, D, M, notice that the units digit
only the first 3 characters (I. V, X), the tens digit uses 3rd
through 5th characters (X, L, C), and the hundreds digit uses the 5th
through 7th (C, D, M). The program uses this
consistent pattern. Check the code to see how.
Addendum October 8,2005: Finally got
around to adding number conversions from Roman back to Arabic at a user's
request. A bit more complicated because there are many ways to form
invalid Roman numerals using valid letters. In fact a random
collection of digits 1 through 9 will always form a valid Arabic number, but a
random collection of letters I, V, X, L, C, D, M is quite unlikely to form a
valid Roman number.
The lack of a zero placeholder is another
problem. Our conversion code needs to identify that no numeral is
defined for a particular position so we can insert the missing
Running/Exploring the Program
Suggestions for further exploration
Try allowing Arabic numbers up to 9999. Notice
that above 3999, the leading 'M's just keep increasing. (There are
some other conventions using lines over the M's or some such,
but they didn't seem to adapt very well to machine display.)
extension: Modify the program to convert Roman numerals back to
Arabic. (I haven't written this code yet - but I'll bet it's
|Created: September 8, 2000
Modified: July 29, 2017