$24
Write a C program lab3.c that operates as follows. Your program will read an integer number, which should be in the range from 1 to 3999. If the input value is out of range, just print the error message as shown below. Otherwise your program should print the equivalent Roman numeral.
Your program should first separate the input number into four digits using arithmetic operations (such as / and %). Then form the equivalent Roman numeral by printing the corresponding sequences of characters as follows. Digits with value 0 do not produce any characters.
Thousands
Hundreds
Tens
Units
1000
→ M
100→C
10
→ X
1
→ I
2000
→ MM
200 → CC
20
→ XX
2
→ II
3000
→ MMM
300 → CCC
30
→ XXX
3
→ III
400
→ CD
40
→ XL
4
→ IV
500
→ D
50
→ L
5
→ V
600
→ DC
60
→ LX
6
→ VI
700
→ DCC
70
→ LXX
7
→ VII
800
→ DCCC
80
→ LXXX
8
→ VIII
900
→ CM
90
→ XC
9
→ IX
Here are some example inputs and corresponding expected outputs:
-1 → The number -1 is too small
0 → The number 0 is too small
1 → I
10→X
22 → XXII
100→C
203 → CCIII
330 → CCCXXX
444 → CDXLIV
1000 → M
1005 → MV
1050 → ML
2066 → MMLXVI
2500 → MMD
2607 → MMDCVII
3770 → MMMDCCLXX
3888 → MMMDCCCLXXXVIII
3999 → MMMCMXCIX
4000 → The number 4000 is too large
10000 → The number 10000 is too large
Please carefully read the following requirements:
Try to write the program individually, because you will learn more that way. However, if you get stuck and don’t know how to proceed, you can ask the instructor or a classmate for assistance.
You may demonstrate your program either on your local machine or on the cs-intro.ua.edu server.
Once you believe your program runs correctly using all the above examples, demonstrate your program to the instructor. If the instructor agrees that your program works correctly, you are done.