Output: IX
Input : 40
Output : XL
Input: 1904
Output : MCMIV
Following is the list of Roman symbols which include subtractive cases also:
SYMBOL-VALUE
I 1
IV 4
V 5
IX 9
X 10
XL 40
L 50
XC 90
C 100
CD 400
D 500
CM 900
M 1000
Simple Input: 3549
Simple Output: MMMDXLIX
Explanation:
- Step 1
- Initially number = 3549
- Since 3549 >= 1000 ; largest base value will be 1000 initially.
- Divide 3549/1000. Quotient = 3, Remainder =549. The corresponding symbol Mwill be repeated thrice.
- Now, number = 549
- 1000 > 549 >= 500 ; largest base value will be 500.
- Divide 549/500. Quotient = 1, Remainder =49. The corresponding symbol D will be repeated once.
- Now, number = 49
- 50 > 49 >= 40 ; largest base value is 40.
- Divide 49/40. Quotient = 1, Remainder = 9. The corresponding symbol XL will be repeated once.
- Now, number = 9
- 10> 9 >= 9 ; largest base value is 9.
- Divide 9/9. Quotient = 1, Remainder = 0. The corresponding symbol IX will be repeated once.
- Finally, the number becomes 0, the algorithm stops here.
- The output obtained MMMDXLIX.
Step 2
Step 3
Step 4
Step 5
Simple Code:
0 Comments
If you have any doubts, Please let me know