TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Convert Decimal To Roman using Dictionary
Saurav Mittal
Sep 08
2014
Code
1.6
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
namespace
CSharpPractice
{
class
Class1
{
public
static
void
RomanDecimalConvertor(
int
num)
{
Dictionary<
int
,
string
> roman =
new
Dictionary<
int
,
string
>
{
{1,
"I"
}, {4,
"IV"
},
{5,
"V"
}, {9,
"IX"
},
{10,
"X"
}, {40,
"XL"
},
{50,
"L"
}, {90,
"XC"
},
{100,
"C"
}, {400,
"CD"
},
{500,
"D"
}, {900,
"CM"
},
{1000,
"M"
}
};
int
divisor = 0, times = 0;
while
(num!=0)
{
foreach
(
int
key
in
roman.Keys)
{
if
(key > num)
break
;
divisor = key;
}
times = num / divisor;
for
(
int
i = 1; i <= times; i++)
{
Console.Write(roman[divisor]);
}
num = num % divisor;
}
}
}
}
namespace
CSharpPractice
{
class
Program
{
static
void
Main(
string
[] args)
{
Class1.RomanDecimalConvertor(1500);
Console.Read();
}
}
}
C#
Decimal To Roman Conversion
C# Dictionary