ExamAdda Logo

Integer to Roman

Easy

Roman numerals are represented using the following symbols:

I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000

Special subtraction rules are used for the following values:

IV = 4
IX = 9
XL = 40
XC = 90
CD = 400
CM = 900

Given an integer num, convert it to its corresponding Roman numeral representation.

It is guaranteed that the input is within the range from 1 to 3999.

Example 1

Input

3

Output

III

Explanation

3 is represented as III.

Example 2

Input

58

Output

LVIII

Explanation

50 = L

5 = V

3 = III

Therefore, 58 = LVIII.

Constraints

1 ≤ num ≤ 3999

Hints:

Hint 1

Create arrays of Roman numeral values and their corresponding symbols in descending order.

Hint 2

Repeatedly append the largest Roman numeral whose value is less than or equal to the remaining number, then subtract its value until the number becomes zero.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 4, 2026

Last updated

Aug 4, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output