This C Program Converts the given Roman Number to Decimal Number. Roman Number System of representing numbers devised by the ancient Romans. The numbers are formed by combinations of the symbols I, V, X, L, C, D, and M, standing, respectively, for 1, 5, 10, 50, 100, 500, and 1,000 in the Hindu-Arabic numeral system. Decimal is a term that describes the base-10 number system commonly used by lay people in the developed world.

Here is source code of the C program to Convert Roman Number to Decimal Number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to Convert Roman Number to Decimal Number`

`*/`

`#include <stdio.h>`

`#include <string.h>`

int digit(char);

int main()

`{`

char romanval[1000];

int i = 0;

long int number = 0;

printf("Enter roman num (Valid digits are I, V, X, L, C, D, M):\n");

scanf("%s", romanval);

while (romanval[i])

`{`

if (digit(romanval[i]) 2)

`{`

if (digit(romanval[i]) = digit(romanval[i+1]))

number = number + digit(romanval[i]);

`else`

`{`

number = number + (digit(romanval[i + 1]) -

digit(romanval[i]));

`i++;`

`}`

`i++;`

`}`

printf("Its decimal value is : %ld", number);

return 0;

`}`

int digit(char c)

`{`

int value = 0;

switch (c)

`{`

case 'I':

value = 1;

break;

case 'V':

value = 5;

break;

case 'X':

value = 10;

break;

case 'L':

value = 50;

break;

case 'C':

value = 100;

break;

case 'D':

value = 500;

break;

case 'M':

value = 1000;

break;

case '0':

value = 0;

break;

default:

value = -1;

`}`

return value;

`}`

Output: $ cc pgm6.c $ a.out Enter roman num (Valid digits are I, V, X, L, C, D, M): v Invalid roman digit : v $ a.out Enter roman num (Valid digits are I, V, X, L, C, D, M): D Its decimal value is : 500

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.