-
Notifications
You must be signed in to change notification settings - Fork 0
/
yearToRoman.c
65 lines (56 loc) · 1.11 KB
/
yearToRoman.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
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
/*Program to convert any year in the Gregorian calendar to year in Roman numerals; AUTHOR: rapteon; DATE: 13June2019*/
#include<stdio.h>
void convertYear(int year){
int i, v, x, l, d, c, m;
/*Weird logic which makes sense using pen & paper😶️*/
m = year/1000;
d = (year%1000)/500;
c = ((year%1000)%500)/100;
l = (((year%1000)%500)%100)/50;
x = ((((year%1000)%500)%100)%50)/10;
v = (((((year%1000)%500)%100)%50)%10)/5;
i = (((((year%1000)%500)%100)%50)%10)%5;
/*Excuse me for this kind of print statements.😅️*/
printf("%d is equivalent to ", year);
while(m > 0){
printf("M");
m--;
}
while(d > 0){
printf("D");
d--;
}
while(c > 0){
printf("C");
c--;
}
while(l > 0){
printf("L");
l--;
}
while(x > 0){
printf("X");
x--;
}
while(v > 0){
printf("V");
v--;
}
while(i > 0){
printf("I");
i--;
}
printf("\n");
}
//Main function begins...
int main(){
int year;
char choice = 'Y';
while(choice == 'Y' || choice == 'y'){
printf("Enter year: ");
scanf("%d", &year);
convertYear(year);
printf("Enter another year? [Y/n]: ");
scanf(" %c", &choice);
}
}