bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / letusc / lucproblem013.c

lucproblem013.c (889B)


      1 /* Define a function to convert any given year into its Roman equivalent.
      2 Use these roman equivalent for decimal numbers : 1 - I, 5 - V, 10 - X,
      3 50 - L, 100 - C, 500 - D, 1000 - M */
      4 /* Let Us C, Chap - 8, Page - 141, Problem 8.3 */
      5 
      6 #include <stdio.h>
      7 
      8 void romanise(int);
      9 
     10 void romanise(int year)
     11 {
     12     int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
     13     const char *romanChar[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
     14     // including the two-character subtractive pairs.
     15     int i = 0;
     16 
     17     printf("Year %d = ", year);
     18     while (year > 0)
     19     {
     20         if (year >= values[i])
     21         {
     22             printf("%s", romanChar[i]);
     23             year -= values[i];
     24         }
     25         else
     26             i++;
     27     }
     28 }
     29 
     30 int main()
     31 {
     32     int year;
     33     printf("Enter the year : ");
     34     scanf("%d", &year);
     35     romanise(year);
     36     return 0;
     37 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror