How to resolve the algorithm Roman numerals/Encode step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Roman numerals/Encode step by step in the XPL0 programming language
Table of Contents
Problem Statement
Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.
In Roman numerals:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Roman numerals/Encode step by step in the XPL0 programming language
Source code in the xpl0 programming language
proc Rom(N, A, B, C); \Display 1..9 in Roman numerals
int N, A, B, C, I;
[case N of
9: [ChOut(0, C); ChOut(0, A)]; \XI
8,7,6,5:[ChOut(0, B); for I:= 1 to rem(N/5) do ChOut(0, C)]; \V
4: [ChOut(0, C); ChOut(0, B)] \IV
other for I:= 1 to N do ChOut(0, C); \I
];
proc Roman(N); \Display N in Roman numerals
int N, Q;
[Q:= N/1000; N:= rem(0); \0..3999
Rom(Q, ^?, ^?, ^M);
Q:= N/100; N:= rem(0); \0..999
Rom(Q, ^M, ^D, ^C);
Q:= N/10; N:= rem(0); \0..99
Rom(Q, ^C, ^L, ^X);
Rom(N, ^X, ^V, ^I); \0..9
];
int Tbl, I;
[Tbl:= [1990, 2008, 1666, 0, 1, 3999, 2020, 1234];
for I:= 0 to 7 do
[IntOut(0, Tbl(I)); Text(0, ". "); Roman(Tbl(I)); CrLf(0)];
]
You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the Julia programming language
You may also check:How to resolve the algorithm Abstract type step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Proper divisors step by step in the PL/I programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Julia programming language
You may also check:How to resolve the algorithm Undefined values step by step in the Kotlin programming language