I\'m trying to write a function that converts numbers to roman numerals. This is my code so far; however, it only works with numbers that are less than 400. Is there a quick
This should be the simplest solution.
public string IntToRoman(int num)
{
var result = string.Empty;
var map = new Dictionary
{
{"M", 1000 },
{"CM", 900},
{"D", 500},
{"CD", 400},
{"C", 100},
{"XC", 90},
{"L", 50},
{"XL", 40},
{"X", 10},
{"IX", 9},
{"V", 5},
{"IV", 4},
{"I", 1}
};
foreach (var pair in map)
{
result += string.Join(string.Empty, Enumerable.Repeat(pair.Key, num / pair.Value));
num %= pair.Value;
}
return result;
}