Problem 63. Encode Roman Numerals

Created by Cody Team in Cody Challenge

Create a function taking a non-negative integer as its parameter and returning a string containing the Roman Numeral representation of that integer.

By convention, "modern" Roman numerals are written by expressing each digit separately starting with the leftmost digit and skipping any digit with a value of zero.


  • If n is 1990 then romStr = 'MCMXC' since 1000=M, 900=CM, 90=XC.
  • If n is 2008 then romStr = 'MMVIII' since 2000=MM, 8=VIII.
  • If n is 1666 then romStr = 'MDCLXVI'.
  • If n is 0 then romStr is empty ([] and '' are both acceptable)

n will always be an integer between 0 and 3999 (inclusive).

This problem is adapted from Rosetta Code.

Solution Stats

59.69% Correct | 40.31% Incorrect
Last solution submitted on Dec 12, 2018

Problem Comments

Solution Comments

Recent Solvers418

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!