Convert an integer into its Roman numeral representation.
Roman to Integer
gfgGiven a positive integer, convert it to a Roman numeral string.
Roman numerals use the following symbols:
| Symbol | Value |
|---|---|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
Roman numerals are formed by combining symbols from largest value to smallest value. Some values use subtractive notation:
IVIXXLXCCDCMWrite a program that returns the Roman numeral for the given integer.
num.num is a positive whole number.num in Roman numerals.num > 0num is typically within the range representable with the standard symbols.Example 1
Input
58
Output
LVIII
Explanation
50 + 5 + 1 + 1 + 1 = 58, so the numeral is L + V + III = LVIII.
Example 2
Input
1994
Output
MCMXCIV
Explanation
1994 = 1000 + 900 + 90 + 4, which maps to M + CM + XC + IV.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.