> For the complete documentation index, see [llms.txt](https://blog.bernardw.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.bernardw.com/problems/integer-to-roman.md).

# Integer to Roman

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

{% tabs %}
{% tab title="Scala" %}

```scala
val M = Array("", "M", "MM", "MMM")
val C = Array("", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM")
val X = Array("", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC")
val I = Array("", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX")

/**
  *
  * @param num
  * @return
  */
def intToRoman(num: Int):String = {
  if (num < 0 || num > 3999) throw new Error("out of range")
  else {
    M(num/1000) + C((num%1000)/100) + X((num%100)/10) + I(num%10)
  }
}

intToRoman(3745)
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}
