-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_to_roman.cpp
More file actions
90 lines (74 loc) · 1.97 KB
/
number_to_roman.cpp
File metadata and controls
90 lines (74 loc) · 1.97 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
using namespace std;
int main(){
int num, units, tens, hundreds;
cout << "Enter a number: " << endl;
cin >> num;
while(true){
units = num % 10; num /= 10;
tens = num % 10; num /= 10;
hundreds = num % 10; num /= 10;
switch (hundreds) {
case 1: cout << "C";
break;
case 2: cout << "CC";
break;
case 3: cout << "CCC";
break;
case 4: cout << "CD";
break;
case 5: cout << "D";
break;
case 6: cout << "DC";
break;
case 7: cout << "DCC";
break;
case 8: cout << "DCCC";
break;
case 9: cout << "CM";
}
switch (tens) {
case 1: cout << "X";
break;
case 2: cout << "XX";
break;
case 3: cout << "XXX";
break;
case 4: cout << "XL";
break;
case 5: cout << "L";
break;
case 6: cout << "LX";
break;
case 7: cout << "LXX";
break;
case 8: cout << "LXXX";
break;
case 9: cout << "XC";
}
switch (units) {
case 1: cout << "I";
break;
case 2: cout << "II";
break;
case 3: cout << "III";
break;
case 4: cout << "IV";
break;
case 5: cout << "V";
break;
case 6: cout << "VI";
break;
case 7: cout << "VII";
break;
case 8: cout << "VIII";
break;
case 9: cout << "IX";
}
cout << endl;
cout << "Enter a number: " << endl;
cin >> num;
}
system("pause");
return 0;
}