15+ CPP Decimal to Roman Converters

This post contains a total of 15+ Hand-Picked C++ Decimal to Roman Converter Examples with Source Code. All the Decimal to Roman Converters are made using C++ Programming language.

You can use the source codes of the programs given below for your own personal or educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Roman

Made by Roman. CPP Program to Convert Decimal number to Roman Numerals. ( Source )

#include <iostream>
using namespace std;

int main() {
int num;
cin >> num;
int m = num/1000;
int c = (num-m*1000)/100;
int d = (num-m*1000-c*100)/10;
int u = (num-m*1000-c*100-d*10);
    string mr;
    string cr;
    string dr;
    string ur;
    if (num>0 && num<=3999){
    switch (m){
    case 0:
    mr = "";
    break;
    case 1:
     mr = "M";
    break;
    case 2:
     mr = "MM";
    break;
    case 3:            
    mr = "MMM";
    break;
    }
    
    switch (c){
    case 0:
    cr = "";
    break;
    case 1:
    cr = "C";
    break;
    case 2:
    cr = "CC";
    break;
    case 3:            
    cr = "CCC";
    break;
    case 4:
    cr = "CD";
    break;
    case 5:
    cr = "D";
    break;
    case 6:
    cr = "DC";
    break;
    case 7:
    cr = "DCC";
    break;
    case 8:
    cr = "DCCC";
    break;
    case 9:
    cr = "CM";
    break;
    }
    
    switch (d){
    case 0:
    dr = "";
    break;
    case 1:
    dr = "X";
    break;
    case 2:
    dr = "XX";
    break;
    case 3:            
    dr = "XXX";
    break;
    case 4:
    dr = "XL";
    break;
    case 5:
    dr = "L";
    break;
    case 6:
    dr = "LX";
    break;
    case 7:
    dr = "LXX";
    break;
    case 8:
    dr = "LXXX";
    break;
    case 9:
    dr = "XC";
    break;
    }
    switch (u){
    case 0:
    ur = "";
    break;
    case 1:
    ur = "I";
    break;
    case 2:
    ur = "II";
    break;
    case 3:            
    ur = "III";
    break;
    case 4:
    ur = "IV";
    break;
    case 5:
    ur = "V";
    break;
    case 6:
    ur = "VI";
    break;
    case 7:
    ur = "VII";
    break;
    case 8:
    ur = "VIII";
    break;
    case 9:
    ur = "IX";
    break;
    }
    
    cout << num << " equivale a " << mr << cr << dr << ur << " en numeros romanos." << endl;
    }
    
    else (cout << "No existe tal numero en numeracion romana" <<endl);
        
        
    
    
    
    
    return 0;

}

2. By Naman Sharma

Made by Naman Sharma. ( Source )

#include <iostream>
#include <map>
#include <string>
#include <cmath>
using namespace std;


string GetRomanNumber(int number)
{
    map<int, string> 
    decimal2Roman {{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"}};
    map<int, string>::reverse_iterator it;
    string roman="";
    for(it = decimal2Roman.rbegin(); it != decimal2Roman.rend(); it++)
    {
        while(number >= it->first)
        {
            number -= it->first;
            roman  += it->second;
        }
    }
    return roman;
}

int main() {
    int n;
    cout <<"Enter a decimal number: ";
    cin>>n;
    cout<<"\nThe Roman Equivalent is: "<<GetRomanNumber(n)<<"\n";
    
	return 0;
}

3. By Swabhiman

Made by Swabhiman. ( Source )


// Decimal to Roman Number Conversion

#include <iostream>
using namespace std;

int roman_Number(int ,int ,char);

int main() {
 int num=8;
// cout<<"Enter a number :";
 //cin>>num;
 cout<<"Roman Number of Your Number is :";
 if(num>=1000)
 num= roman_Number (num,1000,'m');
 if(num>=500)
 num= roman_Number (num,500,'d');
 if(num>=100)
 num= roman_Number (num,100,'c');
 if(num>=50)
 num= roman_Number (num,50,'l');
 if(num>=10)
 num= roman_Number (num,10,'x');
 if(num>=5)
 num= roman_Number (num,5,'v');
 if(num>=1)
 num= roman_Number (num,1,'i'); 
 
    return 0;
}

int roman_Number (int num,int x_Num,char c) {

 if(num==9){
     cout <<"ix";
     return 0;
 }
 if(num==4){
     cout <<"iv";
     return 0;
 }
 
 while(num>= x_Num ){
     cout<<c;
     num=num-x_Num;
 }
 return num;
}

4. By Pure

Made by Pure. Simple Program to convert decimal to roman. ( Source )

#include <iostream>
#include <string>
using namespace std;

int main() {
    double num;
    string roman; 
    string hundreds;
    string tens; 
    string ones; 
    cout << "enter your decimal based number that will convert to roman numerals" << endl;
    cin >> num;
if (num > 0 && num < 200) {
	if (num >=100 && num <=199){
		hundreds = "C";
		num = num - 100;
	}
    if (num >= 90 && num <=99) {
      tens = "XC";
      num = num - 90;
    }
    if (num >= 80 && num <=89) {
      tens = "LXXX";
      num = num - 80;
    }
    if (num >= 70 && num <= 79) {
      tens = "LXX";
      num = num - 70;
    }
    if (num >= 60 && num <= 69) {
      tens = "LX";
      num = num - 60;
    }
    if (num >= 50 && num <= 59) {
      tens = "L";
      num = num - 50;
    }
    if (num >= 40 && num <= 49) {
      tens = "XL";
      num = num - 40;
    }
    if (num >= 30 && num <= 39) {
      tens = "XXX";
      num = num - 30;
    }
    if (num >= 20 && num <= 29) {
      tens = "XX";
      num = num - 20;
    }
    if (num >= 10 && num <= 19) {
      tens = "X";
      num = num - 10;
    }
    if (num == 9) {
      ones = "IX";
      num = num - 9;
    }
    if (num == 8) {
      ones = "VIII";
      num = num - 8;
    }
    if (num == 7) {
      ones = "VII";
      num = num - 7;
    }
    if (num == 6) {
      ones = "VI";
      num = num - 6;
    }
    if (num == 5) {
      ones = "V";
      num = num - 5;
    }
    if (num == 4) {
      ones = "IV";
      num = num - 4;
    }
    if (num == 3) {
      ones = "III";
      num = num - 3;
    }
    if (num == 2) {
      ones = "II";
      num = num - 2;
    }
    if (num == 1) {
      ones = "I";
      num = num - 1;
    }
}
else 
{
    cout << "Invalid." << endl;
}
roman = hundreds + tens + ones; 
cout << roman << endl; 
return 0;
}

5. By Roman

Made by Roman. ( Source )

#include <iostream>
#include <string>
using namespace std;

void pasaje(int fila, int num){

    string f[4][3] = {
        {"M","",""},
        {"C","D","M"},
        {"X","L","C"},
        {"I","V","X"}
    };
    
    string l1 = f[fila][0];
    string l2 = f[fila][1];
    string l3 = f[fila][2];
    
    string k[10] = {
        "", 
        l1, 
        l1 + l1, 
        l1 + l1 + l1,
        l1 + l2,
        l2,
        l2 + l1,
        l2 + l1 + l1,
        l2 + l1 + l1 + l1,
        l1 + l3
        };
    
    cout << k[num];
    
}

int main() {
int num;
cin >> num;
int m = num/1000;
int c = (num-m*1000)/100;
int d = (num-m*1000-c*100)/10;
int u = (num-m*1000-c*100-d*10);
    
    if (num>0 && num<=3999){
    cout << num << " equivale a " ;
    pasaje (0,m);
    pasaje (1,c);
    pasaje (2,d);
    pasaje (3,u);
    cout << " en numeros romanos." << endl;
    }
    
    else (cout << "No existe tal numero en numeracion romana" <<endl);
        
  return 0;

}

6. By Roman 2.0

Made by Roman 2.0. ( Source )

#include <iostream>
#include <string>
using namespace std;

void pasaje(int dig, int num){

string l1;
string l2;
string l3;
    switch (dig){
    case 4:
    l1 = "M";
    break;
    case 3:
    l1 = "C";
    l2 = "D";
    l3 = "M";
    break;
    case 2:
    l1 = "X";
    l2 = "L";
    l3 = "C";
    break;
    case 1:
    l1 = "I";
    l2 = "V";
    l3 = "X";
    break;
    }
    
    switch (num){
    case 0:
    cout << "";
    break;
    case 1:
    cout << l1;
    break;
    case 2:
    cout << l1 << l1;
    break;
    case 3:            
    cout << l1 << l1 << l1;
    break;
    case 4:
    cout << l1 << l2;
    break;
    case 5:
    cout << l2;
    break;
    case 6:
    cout << l2 << l1;
    break;
    case 7:
    cout << l2 << l1 << l1;
    break;
    case 8:
    cout << l2 << l1 << l1 << l1;
    break;
    case 9:
    cout << l1 << l3;
    break;
    }
    
}



int main() {
int num;
cin >> num;
int m = num/1000;
int c = (num-m*1000)/100;
int d = (num-m*1000-c*100)/10;
int u = (num-m*1000-c*100-d*10);
    
    if (num>0 && num<=3999){
    cout << num << " equivale a " ;
    pasaje (4,m);
    pasaje (3,c);
    pasaje (2,d);
    pasaje (1,u);
    cout << " en numeros romanos." << endl;
    }
    
    else (cout << "No existe tal numero en numeracion romana" <<endl);
        
        
  return 0;

}

7. By voki

Made by voki. ( Source )

#include <iostream>
#include <string>
#include <vector>

//predefinitions of functions
void breakTheNumber(int);
int getOnes(int);
int getTens(int);
int getHundreds(int);
int getThousends(int);

int main()
{
    std::cout << "Decimal to Roman number conventor. Enter a number up to 9,999 to convert.\n";
    int userNumber{ 0 };
    char answer{ 'n' };

    do {
        std::cout << "\nEnter your number: \t";
        std::cin >> userNumber;
        //send the number to function to break it to ones, tens, hundreds, thousends
        breakTheNumber(userNumber);

        std::cout << "\nWould you like to try another number? (y/n) \n";
        std::cin >> answer;

    } while (answer == 'y');

    return 0;
}

void breakTheNumber(int num)
{
    //vectors of strings with roman numbers
    std::vector<std::string> ones{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" };
    std::vector<std::string> tens {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
    std::vector<std::string> hundreds {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };
    std::vector<std::string> thousends {"", "M", "MM", "MMM", "MMMM", "MMMMM", "MMMMMM", "MMMMMMMM", "MMMMMMMMM", "MMMMMMMMMM" };
    
    //call functions to get tens, hundreds...
    int onesNum{ getOnes(num) };
    int tensNum{ getTens(num) };
    int hundredsNum{ getHundreds(num) };
    int thousendsNum{ getThousends(num) };

    std::cout << "Your number(" << num << ") is in Roman: " << thousends[thousendsNum];
    std::cout << hundreds[hundredsNum] << tens[tensNum] << ones[onesNum] << std::endl;

}

int getOnes(int num) 
{
    return(num % 10);
}

int getTens(int num)
{    
    //check if num bigger than 10
    if (num >= 10)
    {
        //need to divide by ten to get tens and get modulus of 10 to get only tens, not hundreds...
        int tens{ num / 10 };
        return (tens % 10);
    }
    else
        return 0;
}

int getHundreds(int num)
{
    if (num >= 100)
    {
        int hundreds{ num / 100 };
        return (hundreds % 10);
    }
    else
        return 0;
}

int getThousends(int num)
{
    if (num >= 1000)
    {
        int thousend{ num / 1000 };
        return (thousend % 10);
    }
    else
        return 0;
}

8. By MO AHSAN AHMAD

Made by MO AHSAN AHMAD. ( Source )

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int num;
	cout<<"\nenter a number : ";
	cin>>num;
	cout<<"\nRoman symbol is : ";
	while(num!=0)
	{
		if(num>=1000)
		{
			cout<<"m";
			num-=1000;
		}
		else if(num>=900)
		{
			cout<<"cm";
			num-=900;
		}
		else if(num>=500)
		{
			cout<<"d";
			num-=500;
		}
		else if(num>=400)
		{
			cout<<"cd";
			num-=400;
		}
		else if(num>=100)
		{
			cout<<"c";
			num-=100;
		}
		else if(num>=90)
		{
			cout<<"xc";
			num-=90;
		}
		else if(num>=50)
		{
			cout<<"l";
			num-=50;
		}
		else if(num>=40)
		{
			cout<<"xl";
			num-=40;
		}
		else if(num>=10)
		{
			cout<<"x";
			num-=10;
		}
		else if(num>=9)
		{
			cout<<"ix";
			num-=9;
		}
		else if(num>=5)
		{
			cout<<"v";
			num-=5;
		}
		else if(num>=4)
		{
			cout<<"iv";
			num-=4;
		}
		else if(num>=1)
		{
			cout<<"i";
			num-=1;
		}
	}
	return 0;
	
}

9. By Pure

Made by Pure. ( Source )

#include <iostream>
#include <string>
using namespace std;

int main() {
    
    int decbaseNum;
    int romanNum;
    cout << "This program converts your Decimal Based Numbers to Roman Numerals" << endl;
    cout << "Please enter a number from 1 to 99" << endl;
    cin >> decbaseNum;
    cout << "Your input was " << decbaseNum << endl;

    cout << decbaseNum << " is converted to " << endl;
    switch (decbaseNum)
    {   
        case 1: cout << "I";
            break;
        case 2: cout << "II";
            break;
        case 3: cout << "III";
            break;
        case 4: cout << "IV";
            break;
        case 5: cout << "V";
            break;
        case 6: cout << "VI";
            break;
        case 7: cout << "VII";
            break;
        case 8: cout << "VIII";
            break;
        case 9: cout << "IX";
            break;
        case 10: cout << "X";
            break;
        
        case 11: cout << "XI";
            break;
        case 12: cout << "XII";
            break;
        case 13: cout << "XIII";
            break;
        case 14: cout << "XIV";
            break;
        case 15: cout << "XV";
            break;
        case 16: cout << "XVI";
            break;
        case 17: cout << "XVII";
            break;
        case 18: cout << "XVIII";
            break;
        case 19: cout << "XIX";
            break;
        case 20: cout << "XX";
            break;
        
        case 21: cout << "XXI";
            break;
        case 22: cout << "XXII";
            break;
        case 23: cout << "XXIII"; 
            break;
        case 24: cout << "XXIV";
            break;
        case 25: cout << "XXV";
            break;
        case 26: cout << "XXVI";
            break;
        case 27: cout << "XXVII"; 
            break;
        case 28: cout << "XXVIII";
            break;
        case 29: cout << "XXIX";
            break;
        case 30: cout << "XXX";
            break;
        
        case 31: cout << "XXXI";
            break;
        case 32: cout << "XXXII";
            break;
        case 33: cout << "XXXIII";
            break;
        case 34: cout << "XXXIV";
            break;
        case 35: cout << "XXXV";
            break;
        case 36: cout << "XXXVI";
            break;
        case 37: cout << "XXXVII";
            break;
        case 38: cout << "XXXVIII";
            break;
        case 39: cout << "XXXIX";
            break;
        case 40: cout << "XL";
            break;
        
        case 41: cout << "XLI";
            break;
        case 42: cout << "XLII";
            break;
        case 43: cout << "XLIII";
            break;
        case 44: cout << "XLIV";
            break;
        case 45: cout << "XLV";
            break;
        case 46: cout << "XLVI";
            break;
        case 47: cout << "XLVII";
            break;
        case 48: cout << "XLVIII";
            break;
        case 49: cout << "XLIX";
            break;
        case 50: cout << "L";
            break;
        
        case 51: cout << "LI";
            break;
        case 52: cout << "LII";
            break;
        case 53: cout << "LIII";
            break;
        case 54: cout << "LIV";
            break;
        case 55: cout << "LV";
            break;
        case 56: cout << "LVI";
            break;
        case 57: cout << "LVII";
            break;
        case 58: cout << "LVIII";
            break;
        case 59: cout << "LIX";
            break;
        case 60: cout << "LX";
            break;
        
        case 61: cout << "LXI";
            break;
        case 62: cout << "LXII";
            break;
        case 63: cout << "LXIII";
            break;
        case 64: cout << "LXIV";
            break;
        case 65: cout << "LXV";
            break;
        case 66: cout << "LXVI";
            break;
        case 67: cout << "LXVII";
            break;
        case 68: cout << "LXVIII";
            break;
        case 69: cout << "LXIX";
            break;
        case 70: cout << "LXX";
            break;
        
        case 71: cout << "LXXI";
            break;
        case 72: cout << "LXXII";
            break;
        case 73: cout << "LXXIII";
            break;
        case 74: cout << "LXXIV";
            break;
        case 75: cout << "LXXV";
            break;
        case 76: cout << "LXXVI";
            break;
        case 77: cout << "LXXVII";
            break;
        case 78: cout << "LXXVIII";
            break;
        case 79: cout << "LXXIX";
            break;
        case 80: cout << "LXXX";
            break;
        
        case 81: cout << "LXXXI";
            break;
        case 82: cout << "LXXXII";
            break;
        case 83: cout << "LXXXIII";
            break;
        case 84: cout << "LXXXIV";
            break;
        case 85: cout << "LXXXV";
            break;
        case 86: cout << "LXXXVI";
            break;
        case 87: cout << "LXXXVII";
            break;
        case 88: cout << "LXXXVIII";
            break;
        case 89: cout << "LXXXIX";
            break;
        case 90: cout << "XC";
            break;
        
        case 91: cout << "XCI";
            break;
        case 92: cout << "XCII";
            break;
        case 93: cout << "XCIII";
            break;
        case 94: cout << "XCIV";
            break;
        case 95: cout << "XCV";
            break;
        case 96: cout << "XCVI";
            break;
        case 97: cout << "XCVII";
            break;
        case 98: cout << "XCVIII";
            break;
        case 99: cout << "XCIX";
            break;
        default: cout << "You didn't enter a number from 1-99";
    }
	return 0;
}

10. By Ella

Made by Ella. C++ Program for Converting Decimal numbers to Roman Numerals. ( Source )

#include <iostream>
using namespace std;

int main() {
    int var,nx,nv,ni,i;
    //variable, no of X, no of V, no of I
    cout<<"\nEnter no to be converted: \n";
    cout<<"(Only Decimal Numbers less than 50)";
    cin>>var;
    cout<<endl;
    nx=var/10;
    for(i=0;i<nx;i++)
        cout<<'X';
    var%=10;
    if(var==9){
        cout<<"IX";
        return 0;
    }
    nv=var/5;
    for(i=0;i<nv;i++)
        cout<<"V";
    var%=5;
    if(var==4){
        cout<<"IV";
        return 0;
    }
    ni=var;
    for(i=0;i<ni;i++)
        cout<<"I";
    return 0;
}

11. By Fritz Bryan

Made by Fritz Bryan. ( Source )

#include <iostream>

using namespace std;

int main() {
	char val[100];
	int x, y=0;
	
	cout << "Enter a number: ";
	cin >> x;
	
	while(x!=0) {
	    if(x>4000) {
	        cout << "Number is too large.";
	        break;
	    }
		else if(x>=1000) {
			x = x-1000;
			val[y] = 'M';
			y++;
		}
		else if (x>=900) {
			x = x-900;
			val[y] = 'C';
			y++;
			val[y] = 'M';
			y++;
		}
		else if(x>=500) {
			x = x-500;
			val[y] = 'D';
			y++;
		}
		else if(x>=400) {
			x = x-400;
			val[y] = 'C';
			y++;
			val[y] = 'D';
			y++;
		}
		else if(x>=100) {
			x = x-100;
			val[y] = 'C';
			y++;
		}
		else if(x>=90) {
			x = x-90;
			val[y] = 'X';
			y++;
			val[y] = 'C';
			y++;
		}
		else if(x>=50) {
			x = x-50;
			val[y] = 'L';
			y++;
		}
		else if(x>=40) {
			x = x-40;
			val[y] = 'X';
			y++;
			val[y] = 'L';
			y++;
		}
		else if(x>=10) {
			x = x-10;
			val[y] = 'X';
			y++;
		}
		else if(x==9) {
			x = x-9;
			val[y] = 'I';
			y++;
			val[y] = 'X';
			y++;
		}
		else if(x>=5) {
			x = x-5;
			val[y] = 'V';
			y++;
		}
		else if(x>=4) {
			x = x-4;
			val[y] = 'I';
			y++;
			val[y] = 'V';
			y++;
		}
		else if (x>=1) {
			x--;
			val[y] = 'I';
			y++;
		}
	}
	
	if(x<4000) {
	    cout << "Roman Numeral: " << val;
	}
	
	return 0;
}

12. By JulioC OG

Made by JulioC OG. Enter an int number between 1-3999 and this code output a string with the roman equivalent. ( Source )

#include <iostream>
#include "string"
using namespace std;

const string romAns[4][10] = {
    { "", "M", "MM", "MMM" },
    { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
    { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
    { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }
};

int main() {

    string roman = "";
    unsigned int romanArr[4] = {0,0,0,0};
    unsigned int lremindr = 0;
    unsigned int denom = 1;
    
    cin >> lremindr;
    if( lremindr > 0 && lremindr < 4000 ){
    
        for(int i = 0; i < 4; i++){
            switch (i){
                case(0): denom = 1000; break;
                case(1): denom = 100; break;
                case(2): denom = 10; break;
                case(3): denom = 1; break;
            }
            romanArr[i] = lremindr / denom;
            lremindr %= denom;
        }
    
        for(int i = 0; i < 4; i++){
            roman += romAns[i][romanArr[i]];
        }
    }else{ roman = "Out of boundaries!"; }
    
    cout << roman;
    
    return 0;
}

13. By Pasquale Perrone

Made by Pasquale Perrone. ( Source )

#include <iostream>
using namespace std;

int main() {
    int n; char l;
    cin >> n;
    while(n){
        if(n>=1000){
            cout << "M";
            n-=1000;
        }
        else if(n>=500){
            if(n>=900){
                cout << "CM";
                n-=900;
            }
            else{
                cout << "D";
                n-=500;
            }
        }
        else if(n>=100){
            if(n>=400){
                cout << "CD";
                n-=400;
            }
            else{
                cout << "C";
                n-=100;
            }
        }
        else if(n>=50){
            if(n>=90){
                cout << "XC";
                n-=90;
            }
            else{
                cout << "L";
                n-=50;
            }
        }
        else if(n>=10){
            if(n>=40){
                cout << "XL";
                n-=40;
            }
            else{
                cout << "X";
                n-=10;
            }
        }
        else if(n>=5){
            if(n==9){
                cout << "IX";
                n-=9;
            }
            else{
                cout << "V";
                n-=5;
            }
        }
        else{
            if(n==4){
                cout << "IV";
                n-=4;
            }
            else{
                cout << "I";
                n-=1;
            }
        }
    }
    return 0;
}

14. By sparsh

Made by sparsh. ( Source )

#include <bits/stdc++.h>
using namespace std;

// Function to calculate roman equivalent
string intToRoman(int num) 
{   
     // storing roman values of digits from 0-9 
     // when placed at different places
     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"};
        
     // Converting to roman
     string thousands = m[num/1000];
     string hundereds = c[(num%1000)/100];
     string tens =  x[(num%100)/10];
     string ones = i[num%10];
        
     string ans = thousands + hundereds + tens + ones;
        
     return ans;
}

// Driver program to test above function
int main()
{
      int number = 3549;
      cout << intToRoman(number);
      return 0;
}

15. By Mr. Rahul

Made by Mr. Rahul. ( Source )


// C++ Program to convert decimal number to roman 
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
// Function to convert decimal to Roman Numerals
void printRoman(int n)
{
    int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
    string sym[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
    int i=12;    
    while(n>0)
    {
      int div = n/num[i];
      n = n%num[i];
      while(div--)
      {
        cout<<sym[i];
      }
      i--;
    }
}
 
//Driver program
int main()
{
    int n;
    cin >> n;
 
    printRoman(n);
 
    return 0;

}

16. By Andrea Leoni

Made by Andrea Leoni. Program that gets an int number (between 1 and 3000) and converts it into the corresponding roman number. ( Source )

#include <iostream>
using namespace std;
// function that converts the signle digit to roman
void stampch(char,char,char,int);

int main()
{
    cout << "Enter an integer number (between 1 and 3000): ";
    int num;
    cin >> num;
    
    cout << endl << num << " in roman numbers is ";
    
    int num0 = num;
    // THOUSANDS in roman representation
    if(num/1000>0) {
        num /= 1000;
        for(int i=0; i<num; ++i)
            cout << 'M';
        num = num0%1000;
    }
    // HUNDREDS in roman representation
    if(num/100>0) {
        num /= 100;
        stampch('C','D','M',num);
        num = num0%100;    
    }
    // TENS in roman representation
    if(num/10>0) {
        num /= 10;
        stampch('X','L','C',num);
        num = num0%10;    
    }
    
    // ONES in roman representation
    stampch('I','V','X',num);
    
    cout << endl;
        
    return 0;
}

void stampch(char one, char five, char ten, int nch) {
    if(nch==4)
            cout << one << five; // one << five
    else 
        if(nch==9)
            cout << one << ten; // one << ten
        else {
            if(nch>=5)
                cout << five; // five
            for(int i=0; i<(nch%5); ++i)
                cout << one; //one
        }
}