Introduction :
Converting Roman numerals to integer number is a common problem in mathematics. Using the C programming language, you can solve it easily. Roman numeral was originated in ancient Rome. It is a numeral system that uses combinations of letters from the Latin alphabet, such as I, V, X, L, C, D, M to represent the values 1, 5, 10, 50, 100, 500, and 1000 respectively.
In modern arithmetic, they are not commonly used except specific contexts like clock faces, book chapters movie sequels etc. In this article, I shall show you how to convert a roman numeral to integer number in C programming language. Here, I create a C program which converts a roman numeral and display its corresponding integer value on the screen.
About the program :
The C program is a converting program that takes a roman numeral (string) from the user. After that, it converts the input into integer numbers and display the result on the console screen.
Explanation of the program :
At first, you have to include standard input-output library (stdio.h) in the program. Then in the main() function, declare a character array (roman) to store the input value. You have to also declare integer variables such as “num”, “a” and “i”. You can ask the user to enter a roman numeral using printf() function. Using gets() function, take a string input from the user and store it in the “roman” array.
The while loop will be stopped if it faces an end of the string (‘\0’) of the input value. In the while loop, the program checks each character and adds the value to the “num” variable. When a smaller character placed before a larger character, it subtracts the smaller value instead of adding it. If you enter a wrong input, it prints an error message. Otherwise, you can see the converted integer value of roman numeral on the console screen.
How run the program :
You have to install VS Code on your PC to run the program. After that, open VS Code and create a new file like “roman_to_number.c”. After that copy the below code and paste in the “roman_to_number.c” file. Now, save the file and run the program to see the output.
Source code of the program :
This is the source code of converting roman numerals to integer number in C programming language.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main()
{
char roman[100];
int num = 0, a, i = 0;
printf("Enter roman Numeral to convert integer number\n");
gets(roman);
while (roman[i] != '\0')
{
if (roman[i] == 'M')
num = num + 1000;
else if (roman[i] == 'D')
{
num = num + 500;
}
else if (roman[i] == 'C')
{
if (roman[i + 1] == 'D' || roman[i + 1] == 'M')
{
num = num - 100;
}
else
{
num = num + 100;
}
}
else if (roman[i] == 'L')
{
num = num + 50;
}
else if (roman[i] == 'X')
{
if (roman[i + 1] == 'L' || roman[i + 1] == 'C')
{
num = num - 10;
}
else
{
num = num + 10;
}
}
else if (roman[i] == 'V')
{
num = num + 5;
}
else if (roman[i] == 'I')
{
if (roman[i + 1] == 'V' || roman[i + 1] == 'X')
{
num = num - 1;
}
else
{
num = num + 1;
}
}
else
{
printf("You have enter wrong input\n");
return 0;
}
i++;
}
printf("Integer number of roman Numeral %s is %d\n", roman, num);
return 0;
}
Output of the program :
To see the output of the program, you can run the program on your PC.

Conclusion :
At last, you have learned how to convert roman numeral to integer number in C programming language. Now, you can use and modify the above code for your own projects. Thank you for visiting my site.