Syntax
[S,nL]=roman(n)
Input Parameter
Output Parameter
S : | | String of roman number |
nL : | | separated divisor list |
Examples
roman (2012)
Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm converts an integer into its Roman numeral representation. It is implemented in a MATLAB function named roman
. The function takes a single input parameter and returns two outputs.
Input Parameters
- n: An integer number that needs to be converted into a Roman numeral.
Output Results
- S: A string representing the Roman numeral equivalent of the input number.
- nL: A list of separated divisors used in the conversion process.
Algorithm Steps
- Initialize an empty string
S
to build the Roman numeral.
- Calculate the number of thousands (M) in
n
using floor(n/1000)
and append 'M' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 900 or more, append 'CM' to S
and subtract 900 from n
.
- Calculate the number of five hundreds (D) in
n
using floor(n/500)
and append 'D' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 400 or more, append 'CD' to S
and subtract 400 from n
.
- Calculate the number of hundreds (C) in
n
using floor(n/100)
and append 'C' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 90 or more, append 'XC' to S
and subtract 90 from n
.
- Calculate the number of fifties (L) in
n
using floor(n/50)
and append 'L' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 40 or more, append 'XL' to S
and subtract 40 from n
.
- Calculate the number of tens (X) in
n
using floor(n/10)
and append 'X' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 9, append 'IX' to S
and set n
to 0.
- Calculate the number of fives (V) in
n
using floor(n/5)
and append 'V' that many times to S
. Subtract the equivalent value from n
.
- If the remaining
n
is 3 or less, append 'I' that many times to S
. Otherwise, append 'IV' to S
.
- Construct the list
nL
containing the counts of each Roman numeral symbol used: [M, D, C, L, X, V, n].
Algorithm explaination created using ChatGPT on 2025-08-18 23:52. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21