• Home
  • About
    • Cong-Yao Huang's Personal Homepage photo

      Cong-Yao Huang's Personal Homepage

      Moon is a minimal, one column jekyll theme for your blog.

    • Learn More
    • Facebook
    • LinkedIn
    • Instagram
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Homework 4 : Functions

06 May 2018

Reading time ~1 minute

1 Decipering 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 function that can calculate Roman Numeral operations (+,-,*,/) and then print out it’s answer with decimal. Examples of program execution are shown below.

Input two Roman Numerals:
First : MMXIV
Second : MCMXCIX
--------------------------
MMXIV in decimal = 2014
MMCXCIX in decimal = 1999
MMXIV + MMCXCIX = 4013
MMXIV - MMCXCIX = 15
MMXIV * MMCXCIX = 4025986
MMXIV / MMCXCIX = 1.0075
--------------------------


cpphwmathfunctions Share Tweet +1