Chapter 3: Problem 28
Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits \(\begin{array}{ll}\text { I } & 1 \\ \text { V } & 5 \\ \text { X } & 10 \\\ \text { L. } & 50 \\ \text { C } & 100 \\ \text { D } & 500 \\ \text { M } & 1,000\end{array}\) Numbers are formed according to the following rules: a. Only numbers up to 3,999 are represented. b. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. c. The numbers 1 to 9 are expressed \(\begin{array}{ll}\text { I } & \text { 1 } \\ \text { II } & 2 \\ \text { III } & 3 \\ \text { IV } & 4 \\ \text { V } & 5 \\ \text { VI } & 6 \\\ \text { VII } & 7 \\ \text { VIII } & 8 \\ \text { IX } & 9\end{array}\) As you can see, an I preceding a \(V\) or \(X\) is subtracted from the valuc, and you can never have more than three I's in a row. d. Tens and hundreds are done the same way, except that the letters \(\mathrm{X}, \mathrm{L}, \mathrm{C}\) and \(\mathrm{C}\), \(\mathrm{D}, \mathrm{M}\) are used instead of \(\mathrm{I}, \mathrm{V}, \mathrm{X}\), respectively. Your program should take an input, such as 1978 , and convert it to Roman numerals, MCMLXXVIII.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.