-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex14.c
35 lines (29 loc) · 953 Bytes
/
ex14.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Write a program that prints a table of all the Roman numeral equivalents of the decimal numbers in the range 1 to 100.
#include <stdio.h>
void printRoman(int number)
{
// Arrays to hold Roman numerals symbols
char *hundreds[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
char *tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
char *ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
// Convert to Roman numeral
int i = number / 100;
printf("%s", hundreds[i]); // Print hundreds place
number %= 100;
i = number / 10;
printf("%s", tens[i]); // Print tens place
number %= 10;
printf("%s", ones[number]); // Print ones place
}
int main()
{
printf("Decimal\tRoman\n");
printf("-------\t-----\n");
for (int i = 1; i <= 100; ++i)
{
printf("%d\t", i);
printRoman(i);
printf("\n");
}
return 0;
}