How to resolve the algorithm Roman numerals/Encode step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Roman numerals/Encode step by step in the Icon and Unicon 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 Icon and Unicon programming language

Source code in the icon programming language

link numbers   # commas, roman

procedure main(arglist)
every x := !arglist do
   write(commas(x), " -> ",roman(x)|"*** can't convert to Roman numerals ***")
end


procedure roman(n)		#: convert integer to Roman numeral
   local arabic, result
   static equiv

   initial equiv := ["","I","II","III","IV","V","VI","VII","VIII","IX"]

   integer(n) > 0 | fail
   result := ""
   every arabic := !n do
      result := map(result,"IVXLCDM","XLCDM**") || equiv[arabic + 1]
   if find("*",result) then fail else return result
end


  

You may also check:How to resolve the algorithm Ternary logic step by step in the Pascal programming language
You may also check:How to resolve the algorithm Array length step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Validate International Securities Identification Number step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the Pascal programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the Phix programming language