10+ C Decimal to Roman Converters

This post contains a total of 10+ 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 these programs for your own personal or educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By แŽทแ’.แˆแŽงแŽดแ‹แ’

Made by แŽทแ’.แˆแŽงแŽดแ‹แ’. C Program to convert Decimal number to Roman Numeral. ( Source )

#include <stdio.h>
int roman(int,int,char);
int main(void)
{
       int num;
       printf("Enter a decimal no :");
       scanf("%d",&num);
       if(num>=1000)
                num = roman(num,1000,'m');
       if(num>=500)
               num = roman(num,500,'d');
       if(num>=100)
               num = roman(num,100,'c');
       if(num>=50)
               num = roman(num,50,'l');
       if(num>=10)
               num = roman(num,10,'x');
       if(num>=5)
               num = roman(num,5,'v');
       if(num>=1)
               roman(num,1,'i');
       printf("\n");
return 0;
}   
int roman(int n,int k,char c)   
{
      if(n==9)
      {
             printf("ix");
             return 0;
      }
      if(n==4)
      {
              printf("iv");
              return 0;
      }
      while(n>=k)
      {
              printf("%c",c);
               n=n-k;
    
     }
     return n;
}

2. By Himanshu Pawar

Made by Himanshu Pawar. ( Source )

//
//
//To convert entered number into roman numeral...
//
//
#include <stdio.h>
main()
{
    int x;
    scanf("%d",&x);
    
    while(x)
    {
        if(x>=900)
        {
            if(x<1000){printf("CM");x-=900;}
            else if(x>=1000){printf("M");x-=1000;}
        }
        else if(x>=400)
        {
            if(x<500){printf("CD");x-=400;}
            else if(x>=500){printf("D");x-=500;}
        }
        else if(x>=90)
        {
            if(x<100){printf("XC");x-=90;}
            else if(x>=100){printf("C");x-=100;}
        }
        else if(x>=40)
        {
            if(x<50){printf("XL");x-=40;}
            else if(x>=50){printf("L");x-=50;}
        }
        else if(x>=9)
        {
            if(x<10){printf("IX");x-=9;}
            else if(x>=10){printf("X");x-=10;}
        }
        else if(x>=4)
        {
            if(x<5){printf("IV");x-=4;}
            else if(x>=5){printf("V");x-=5;}
        }
        else
        {
            printf("I");
            x--;
        }
    }
}

3. By Md.Danial Islam

Made by Md.Danial Islam. ( Source )

#include <stdio.h>

int main() {
  int a;
  printf("Enter The decimal no:(1-20)\n");
  scanf("%d",&a);
if(a==1){
     printf ("The Roman sign of %d is I\n",a);
 }
else if(a==2){
     printf ("The Roman sign of %d is II\n",a);
 } 
else if(a==3){
     printf ("The Roman sign of %d is III\n",a);
 } 
  else if(a==4){
     printf ("The Roman sign of %d is IV\n",a);
 } 
 else if(a==5){
     printf ("The Roman sign of %d is V\n",a);
 } 
else if(a==6){
     printf ("The Roman sign of %d is VI\n",a);
 } 
else if(a==7){
     printf ("The Roman sign of %d is VII\n",a);
 } 
 else if(a==8){
     printf ("The Roman sign of %d is VIII\n",a);
 } 
 else if(a==9){
     printf ("The Roman sign of %d is IX\n",a);
 } 
    else if(a==10){
     printf ("The Roman sign of %d is X\n",a);
     }
    else if(a==11){
     printf ("The Roman sign of %d is XI\n",a);
     }
    else if(a==12){
     printf ("The Roman sign of %d is XII\n",a);
     }
    else if(a==13){
     printf ("The Roman sign of %d is XIII\n",a);
     }
    else if(a==14){
     printf ("The Roman sign of %d is XIV\n",a);
     }
    else if(a==15){
     printf ("The Roman sign of %d is XV\n",a);
     }
    else if(a==16){
     printf ("The Roman sign of %d is XVI\n",a);
     }
    else if(a==17){
     printf ("The Roman sign of %d is XVI\n",a);
     }
    else if(a==18){
     printf ("The Roman sign of %d is XVII\n",a);   
 } 
    else if(a==19){
     printf ("The Roman sign of %d is XIX\n",a); 
     }
    else if(a==20){
     printf ("The Roman sign of %d is XX\n",a); 
     } 
     else {
     printf ("%d is not between 1 to 20",a);
     }
     return 0;
}

4. By Imad Elakhal

Made by Imad Elakhal. Enter your decimal number in ‘for(i=1; i<=150; i++)’. ( Source )

#include<stdio.h>

int     main(void)
{
    int i, x;
    printf("Decimal  Roman\n");
    printf("Number   Numeral\n");
    printf("-------------------\n");

    for(i=1; i<=150; i++)
    {
        x=i;
        printf("%d        ",x);
        if(x==100) {
            printf("C");
            x=0;
        }
        if(x>=50) {
            printf("L");
            x-=50;
        }
        while(x>=10) {
            printf("X");
            x-=10;
        }
        if(x>=5) {
            if(x%10==9) {
                printf("IX");
                x-=9;
            }
            else {
                printf("V");
                x-=5;
            }   
        }
        while(x>0) 
        {
            if(x%10==4) {
                printf("IV");
                x-=4;
            }
            else {
                printf("I");
                x-=1;
            }
            
        }
        printf("\n");
    }

    return (0);
}

5. By soumen mitra

Made by soumen mitra. The input should be in the range 1-1000. ( Source )

#include <stdio.h>

int main() {
    int num,i,j,k=0;
    //printf("Enter a number = ");
    scanf("%d",&num);
    printf("roman representation of the number is ");
    while(num>0)
    {
        if(num>=1 && num<5)
        {
            if(num==4)
            {
                printf("IV");
            }
            else
            {
                for(i=num;i>0;i--)
                {
                    printf("I");
                }
            }
            k=num;
        }
        if(num>=5 && num<10)
        {
            if(num==9)
            {
                printf("IX");
            }
            else
            {
                printf("V");
                for(i=num-5;i>0;i--)
                {
                    printf("I");
                }
            }
            k=num;

        }
        if(num>=10 && num<50)
        {
            if(num/10==4)
            {
                printf("XL");
            }
            else
            {
                for(i=num/10;i>0;i--)
                {
                    printf("X");
                }
            }
            k=(num/10)*10;
        }
        if(num>=50 && num<100)
        {
            if(num/10==9)
            {
                printf("XC");
            }
            else
            {
                printf("L");
                for(i=num/10-5;i>0;i--)
                {
                    printf("X");
                }
            }
            k=(num/10)*10;
        }
        if(num>=100 && num<500)
        {
            if(num/100==4)
            {
                printf("CD");
            }
            else
            {
                for(i=num/100;i>0;i--)
                {
                    printf("C");
                }
            }
            k=(num/100)*100;
        }
        if(num>=500 && num<1000)
        {
            if(num/100==9)
            {
                printf("CM");
            }
            else
            {
                printf("D");
                for(i=num/100-5;i>0;i--)
                {
                    printf("C");
                }
            }
            k=(num/100)*100;
        }
        if(num==1000)
        {
            printf("M");
            k=num;
        }
        num=num-k;
    }
	return 0;
}

6. By jashpal parmar

Made by jashpal parmar. ( Source )

#include <stdio.h>
void roman(int y)
{
    int k;
    k = y / 1000;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("m");
    }
    int l = y % 1000;
    k = l / 500;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("d");
    }
    
    k = (l % 500) / 100;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("c");
    }
    
    l = (l % 500) % 100;
    k = l / 50;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("l");
    }
    
    l = l % 50;
    k = l / 10;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("x");
    }
    
    l = l % 10;
    k = l / 5;
    if (k > 0)
    {
        for(int i=0;i<k;i++)
            printf("v");
    }
    
    l = l % 5;
    if (l > 0)
    {
        for(int i=0;i<l;i++)
            printf("i");
    }
}
int main() 
{
    int year;
    scanf("%d",&year);
    
    printf("Year in Decimal :\n%d \n",year);
    printf("Year in Roman :\n");
    roman(year);    
    return 0;
}

7. By Pranab Roy

Made by Pranab Roy. ( Source )

#include<stdio.h>

int main()
{
    int x,y,z,n;
    scanf("%d",&n);
    x=n/100;
    n=n%100;
    y=n/10;
    z=n%10;
    if(x==1) printf("C");
    else if(x==2) printf("CC");
    else if(x==3) printf("CCC");
    else if(x==4) printf("CD");
    else if(x==5) printf("D");
    else if(x==6) printf("DC");
    else if(x==7) printf("DCC");
    else if(x==8) printf("DCCC");
    else if(x==9) printf("CM");
    if(y==1) printf("X");
    else if(y==2) printf("XX");
    else if(y==3) printf("XXX");
    else if(y==4) printf("XL");
    else if(y==5) printf("L");
    else if(y==6) printf("LX");
    else if(y==7) printf("LXX");
    else if(y==8) printf("LXXX");
    else if(y==9) printf("XC");
    if(z==1) printf("I");
    else if(z==2) printf("II");
    else if(z==3) printf("III");
    else if(z==4) printf("IV");
    else if(z==5) printf("V");
    else if(z==6) printf("VI");
    else if(z==7) printf("VII");
    else if(z==8) printf("VIII");
    else if(z==9) printf("IX");
    printf("\n");
    return 0;

}

8. By SAURAV KUMAR

Made by SAURAV KUMAR. Program to convert a decimal no to roman no for example: 14 – xiv, 123 – cxxiii. ( Source )

#include <stdio.h>
int roman(int,int,char);
int main() {
    int num;
    scanf("%d",&num);
    printf ("%d in Roman : \n",num);
    if (num >=1000)
        num = roman (num ,1000, 'm');
    if (num >=500)
        num = roman (num ,500, 'd');
    if (num >=100)
        num =roman (num, 100, 'c');
    if (num >=50)
        num = roman (num ,50, 'l');
    if (num >=10)
        num = roman (num ,10, 'x');
    if (num >=5)
        num = roman (num ,5, 'v');
    if (num >=1)
        roman (num ,1,'i');
    return 0;
}
int roman (int n,int m,char c)
{
    if (n==4){
        printf ("iv");
        return 0;}
    if(n==9){
        printf ("ix");
        return 0;
    }
    while (n>=m){
        printf ("%c",c);
        n=n-m;
    }
    return n;
}

9. By Nishith Savla

Made by Nishith Savla. Program to convert any number into its roman equivalant. ( Source )

#include <stdio.h>
void roman();
int main()
{
	int num;
 // User input
	printf ("Enter a number: ");
	scanf ("%i", &num);
	printf ("\n%i ->", num);
	roman(num);
	return 0;
}

void roman(int num)
{
	int numbers[ ] = {1000000, 900000, 500000, 400000, 100000, 90000, 50000, 40000, 10000, 90000, 50000, 40000, 10000, 9000, 5000, 4000 ,1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
	char *symbols[ ] = {"(M)", "(DM)", "(D)", "(CD)", "(C)", "(LC)", "(L)", "(XL)", "(X)", "(IX)","(V)", "(IV)", "M", "DM", "D", "CD","C", "LC", "L", "XL", "X", "IX", "V", "IV", "I"};
	
 if (num < 0)
  printf ("-");

	for (int i = 0; num != 0; i++)
	{
		while (num/numbers[i])
		{
			printf ("%s", symbols[i]);
			num -= numbers[i];
		}
	}
}

10. By Leo_de_River

Made by Leo_de_River. ( Source )

#include <stdio.h>

int main() {
int num;
printf("Enter your decimal number");
scanf("%i", &num);
    return 0;
}

11. By metehannbulut

Made by metehannbulut. ( Source )

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void converter() //Decimal to Roman number converter func.
{
    int number,i= 0;
    char converted[400]={};
    printf("Please enter the number which you want to convert to roman numerals:\n");
    scanf("%d",&number);
    printf("Converted form:");
        while(number>=1000){
            number=number-1000;
            converted[i]= 'M';
            i++;
        }
        if(number<1000 && number>899){
            converted[i]= 'C';
            i++;
            converted[i]= 'M';
            i++;
            number=number-900;
            if (number>10)
                goto fiftys;
        }
        while(number>=500){
            number=number-500;
            converted[i]= 'D';
            i++;
        }
        if(number<500 && number>399){
            converted[i]= 'C';
            i++;
            converted[i]= 'D';
            i++;
            number= number-400;
            goto TensDigit;
        }
        while(number>=100){
            number=number-100;
            converted[i]= 'C';
            i++;
        }
    fiftys:

        if(89<number && number<100){
            converted[i]= 'X';
            i++;
            converted[i]= 'C';
            i++;
            number= number-90;
            goto TensDigit;
        }
        while(number>=50){
            number=number-50;
            converted[i]= 'L';
            i++;
        }
        if(number<50 && number>39){
            converted[i]= 'X';
            i++;
            converted[i]= 'L';
            i++;
            number=number-40;
            goto TensDigit;
        }
    TensDigit:

        while(number>=10){
            number=number-10;
            converted[i]= 'X';
            i++;
        }
        if(number==9){
            converted[i]= 'I';
            i++;
            converted[i]='X';
            i++;
            goto End;
        }
        while(number>=5){
            number=number-5;
            converted[i]= 'V';
            i++;
        }
        if(number==4){
            converted[i]= 'I';
            i++;
            converted[i]='V';
            i++;
            goto End;
        }
        while(number>=1){
            number=number-1;
            converted[i]= 'I';
            i++;
        }
    End:

        for(i=0;i<100;i++){
            printf("%c",converted[i]);
        }

        printf("\n\n\n");
}

int main()  //Our Main func.
{
    int i;

    printf("How many number you want to convert?\n");
    scanf("%d",&i);
    printf("\n");

    for(i;i>0;i--){
        converter();
    }
    printf("Programm will be shutted down in 5 sec");
    sleep(5);
    
    return 0;
}