-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue18.txt
32 lines (26 loc) · 760 Bytes
/
issue18.txt
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
Issue no 18
code convert integer to roman
#include <stdio.h>
void integerToRoman(int num) {
int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
const char* symbols[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
if (num < 1 || num > 3999) {
printf("Input out of range (1 to 3999)\n");
return;
}
for (int i = 0; num > 0; i++) {
int count = num / values[i];
num %= values[i];
for (int j = 0; j < count; j++) {
printf("%s", symbols[i]);
}
}
printf("\n");
}
int main() {
int num;
printf("Enter an integer (1-3999): ");
scanf("%d", &num);
integerToRoman(num);
return 0;
}