lucproblem013.c (1025B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Define a function to convert any given year into its Roman equivalent. 8 Use these roman equivalent for decimal numbers : 1 - I, 5 - V, 10 - X, 9 50 - L, 100 - C, 500 - D, 1000 - M */ 10 /* Let Us C, Chap - 8, Page - 141, Problem 8.3 */ 11 12 #include <stdio.h> 13 14 void romanise(int); 15 16 void romanise(int year) 17 { 18 int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; 19 const char *romanChar[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; 20 // including the two-character subtractive pairs. 21 int i = 0; 22 23 printf("Year %d = ", year); 24 while (year > 0) 25 { 26 if (year >= values[i]) 27 { 28 printf("%s", romanChar[i]); 29 year -= values[i]; 30 } 31 else 32 i++; 33 } 34 } 35 36 int main() 37 { 38 int year; 39 printf("Enter the year : "); 40 scanf("%d", &year); 41 romanise(year); 42 return 0; 43 }