How to Convert Integer Number to Roman Numeral in C Language

Introduction :

Sometime, you have to convert a number to Roman numeral for various purposes. Using the C programming language, you can do it easily. In this article, I shall show you how to convert an integer number (1 to 1000) to a Roman numeral in C programming language. Here, I show you two programs. One is without function and another was created using a function.

What is roman numeral :

The numeral system of ancient Rome is called roman numerals. It is a combination of capital letters such as I, V, X, L, C, D, M etc. Roman numerals are used in various applications such as clock faces, book chapter headings, movie series, sports event and more. The following examples are the numbers and corresponding symbol of roman numerals.

  • 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

About the program :

This is a simple C program that converts an integer number to roman numeral. It converts a number from 1 to 1000 in corresponded roman numeral. When you run the program, it asks you to enter a number. If you enter a number less than or equal to 0, it displays an error message. Otherwise, it converts the number into roman numeral and display the result on the console screen.

Explanation of the program :

You have to include stdio.h in the program. Then, declare three integer variables (“num”, “a” and “i”) in the main() function. Using printf() function, ask the user to enter an integer number. You can use scanf() function to store the input number in “num” variable. You have to use “if else” statement to check the input is less than or equal to zero (0).

If the input number is greater than zero (0), the program converts the integer number to Roman numerals. Here, I use division (/) and modulus (%) operator to break down the integer to display proper symbol of Roman numerals such as M, CM, D, CD, C, etc.

How run the program :

To run the program on your PC, you have to install VS Code. Now, open VS Code and create a new C file like “number_to_roman.c”. After that, copy the below code and paste in the “number_to_roman.c” file. Then, run the program on your PC to see the output.

Source code of the program :

The following code is the source code of converting an integer number (1 to 1000) to a Roman numeral in C programming language.

Converting integer number to Roman using function :

The below code converts an integer number (1 to 1000) to a Roman numeral in C programming language that is created using a function.

Output of the program :

Now, run the program on your PC and see the output of the program like below image.

Output of Convert Integer Number to Roman Numeral in C Language

Conclusion :

After completing the above article, you have learned how to convert an integer number (1 to 1000) to a Roman numeral in the C programming language. Thank you for visiting my site.

Scroll to Top