The name of your C program file must be called arabic.c, files with any other name will not be marked.
Roman numerals are used frequently to indicate dates, in particular the year (for example, MMVI represents the year 2006). There are two main differences between roman and arabic numerals.
Your task for this lab assignment is to convert a roman numeral to its arabic equivalent. To assist you with character input, a sample code readchar.c is provided below that requests from the user a roman numeral (in fact it can be anything you type) and prints out the characters one at a time. It is up to you whether you wish to use the code; it is optional.
#include <stdio.h> int main(void) { char ch; printf("Enter roman numerals: "); do { scanf("%c", &ch); if (ch != '\n') { printf("Printing one character at a time: %c\n", ch); } } while (ch != '\n'); return 0; }
A sample output is shown below.
$ gcc -Wall readchar.c -o readchar $ readchar Enter roman numerals: MMVI Printing one character : M Printing one character : M Printing one character : V Printing one character : I $
Notice that we perform explicit checks for the newline character. Why do you think this is needed?
The conversion is specified using the following cases.
Write a program arabic.c that requests a roman numeral from the user. The input can either be lowercase, uppercase, or a mix of both. A sample run of the program is shown below. User input is denoted in bold.
$ gcc -Wall arabic.c -o arabic $ arabic Enter roman numerals : i The year in arabic is 1. $ arabic Enter roman numerals : MMVI The year in arabic is 2006. $ arabic Enter roman numerals : McMxCvIiI The year in arabic is 1998. $ arabic Enter roman numerals : MMMMMMMMMCMXCIX The year in arabic is 9999. $ arabic Enter roman numerals : mmmmmmmmmdccclxxxviii The year in arabic is 9888. $
A total of 7 different hosts have accessed this document in the last 391 days; your host, 216.73.216.149, has accessed it 1 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.