#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
string dec_to_numeral
(int x)
{
int dec[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string num[13] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
string numeral;
for(int i = 0; i < 13; i++)
{
while (x >= dec[i])
{
x -= dec[i];
numeral.append(num[i]);
}
}
return numeral;
}
int main()
{
int n;
cout<<"Enter a decimal number: ";
cin>>n;
cout <<"Roman = "<< dec_to_numeral(n)<<endl;
system("pause");
return 0;
}
No comments:
Post a Comment