Description :
Given an integer , convert it to a roman number.
Input is graranteed to be within the range from 1 to 3999.
Ans :
#include<iostream>
#include<string>
using namespace std;
string intToRoman(int num)
{
string M[] = {"", "M", "MM", "MMM"};
string C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
}
int main()
{
string strRomanNumber ;
int number ;
while (cin>>number && number< 4000 && number > 0)
{
strRomanNumber = intToRoman(number);
cout << "Integer : " << number
<< "( " <<strRomanNumber
<< " )" <<endl;
}
cout << "--Done--" <<endl;
}