Starting from:

$30

Lab02. Roman Numerals

EE231002 Introduction to Programming
Lab02. Roman Numerals

Roman numerals is a number system used in ancient Rome to represent integer numbers.
In this system, seven letters are used. The letters and their values are shown in the following
table.
Letter I V X L C D M
Value 1 5 10 50 100 500 1000
Note that there is no zero in the table since ancient Roman do not have the concept of zero.
An integer represented in Roman numerals usually take more than one letter. In this case, the
value is usually additive from left to right unless the letter on the immediate right has a larger
value. In the latter case, the smaller value of the left letter is subtracted from the larger value of
the right letter. Using this simple rule, some typical numbers are shown in the table below.
Roman numerals I II III IV V VI VII VIII IX
Decimal values 1 2 3 4 5 6 7 8 9
Roman numerals X XX XXX XL L LX LXX LXXX XC
Decimal values 10 20 30 40 50 60 70 80 90
Roman numerals C CC CCC CD D DC DCC DCCC CM
Decimal values 100 200 300 400 500 600 700 800 900
Please write a C program to read an integer and then print out the Roman numerals with
the same value. Examples of program execution are shown below.
$ ./a.out
Input an integer between 1 and 3000: 888
DCCCLXXXVIII
$ ./a.out
Input an integer between 1 and 3000: 2018
MMXVIII
Notes.
1. Create a directory lab02 and use it as the working directory.
2. Name your program source file as lab02.c.
1
3. The first few lines of your program should be comments as the following.
/* EE231002 Lab02. Roman Numerals
ID, Name
Date: */
4. After finishing editing your source file, you can execute the following command to compile
it,
$ gcc lab02.c
If no compilation errors, the executable file, a.out, should be generated, and you can
execute it by typing
$ ./a.out
5. After you finish verifying your program, you can submit your source code by
$ ∼ee231002/bin/submit lab02 lab02.c
If you see a ”submitted successfully” message, then you are done. In case you want to
check which file and at what time you submitted your labs, you can type in the following
command:
$ ∼ee231002/bin/subrec lab02
It will show the last few submission records.
6. Since loops have not been covered yet, do not use loops in this lab. And because no loops,
program efficiency is not the best. Thus, for this lab only, the execution efficiency is not
emphasized.
2

More products