March 5, 2005
     

Program / Task Name:

   Roman Numerals

Level:

 

 Novice / Advanced

Point Value:

 

 4

Solution(s):

 

 prob04.c

Data File(s):

 

 

 
C programmers: your program name must be: prob04.exe
JAVA programmers: your program name must be: prob04.class

 

Task Description

Many persons are familiar with the Roman numerals for relatively small numbers.  The symbols ``I", ``V", ``X", ``L", and ``C" represent the decimal values 1, 5, 10, 50, and 100 respectively.  To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right.  For example, the number 3 is represented as ``III", and the value 73 is represented as ``LXXIII".  The exceptions to this rule occur for numbers having units values of 4 or 9, and for tens values of 40 or 90.  For these cases, the Roman numeral representations are ``IV" (4), ``IX" (9), ``XL" (40), and ``XC" (90).  So the Roman numeral representations for 24, 39, 44, 49, and 94 are ``XXIV", ``XXXIX", ``XLIV", ``XLIX", and ``XCIV", respectively.

The input will consist of a sequence of integers in the range 1 to 100.

You are to write a program that prompts the user to enter a positive integer and responds by printing out the equivalent Roman Numeral. The program should terminate when the user enters 0.

 

Program Input / Output

Enter a number: 1
The Roman Numeral for 1 is I

Enter a number: 2
The Roman Numeral for 1 is II

Enter a number: 1
The Roman Numeral for 1 is I

Enter a number: 20
The Roman Numeral for 20 is XX

Enter a number: 99
The Roman Numeral for 99 is IC

Enter a number: 0

 

 

 

   
  (c) 2005 Hewlett-Packard Company