Reference no: EM132211108
Write a program to produce a table of decimal numbers and roman numerals from 1 to 1000. The Romans used a special method of showing numbers based on the following symbols I,V,X,L,C,D and M representing 1,5,10,50,100,500 and 1000 respectively.
There are a few rules for roman numerals
(a) To write a roman numeral each of the nonzero digits should be treated separately. For example, to write 651=500+100+50+1, D=500,C=100,L=50,I=1, we have DCLI.
(b) The symbols I,X,C and M (symbols representing powers of 10) can be repeated at most 3 times in succession. D, L and V (symbols not representing powers of 10) can never be repeated.
(c) I can be subtracted from V and X only. X can be subtracted from L and C only. C can be subtracted from D and M only. In other words, symbol representing 10x can be subtracted from symbol representing 5 * 10x and 10 * 10x . V, L and D can never be subtracted.
In other words, symbols not representing powers of 10 can never be subtracted. Your program should produce a table of decimal numbers and corresponding roman numerals. As a starting point find how a decimal number can be represented using numbers which has a roman equivalent. Given a decimal number n find the values of a, b, c, d, e, f, g which satisfies
n = a * 1000 + b * 500 + c * 100 + d * 50 + e * 10 + f * 5 + g * 1
This will give you a roman numeral representation which will be correct in most cases.
For example, 752 = 500 + 2 * 100 + 50 + 2 * 1 can be converted into DCCLII. Since we have 2*100 C repeats and since we have 2*1, I repeats.
After that you can take care of the special cases where a symbol appears 4 or more times or a nonrepeating symbol appears two or more times. Your final program will have several if-else statements.
Sample output for this assignment is as follows
1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VIII
.
.
1000 M