home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20229 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.5 KB  |  50 lines

  1. Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  2. From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Roman Numerals
  5. Date: 26 Jan 1993 19:35:02 GMT
  6. Organization: TH Darmstadt
  7. Lines: 37
  8. Distribution: world
  9. Message-ID: <1k43p6INNjr3@rs2.hrz.th-darmstadt.de>
  10. References: <damatt01.728068722@starbase.spd.louisville.edu>
  11. NNTP-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
  12.  
  13. In article <damatt01.728068722@starbase.spd.louisville.edu>, damatt01@starbase.spd.louisville.edu (David A. Mattingly) writes:
  14. > Does anyone know of an integer-to-Roman-numeral converter? I know I saw one in
  15. > a collection of utilities, maybe on simtel20...
  16.  
  17. Get yourself intercal :)
  18.  
  19. In C this routine should do:
  20.  
  21. #include <stdio.h>
  22.  
  23. int roman(int num)
  24. { static char *letters="IVXLCDMA";
  25.   static int x=0;
  26.   int j;
  27.  
  28.   if (num<=0 || num>=4000) return -1;
  29.   x+=2;
  30.   if (num>=10) roman(num/10); 
  31.   x-=2;
  32.   switch(j=num%10)
  33.   { case 4 : putchar(letters[x]);
  34.              putchar(letters[x+1]);
  35.              break;   
  36.     case 9 : putchar(letters[x]);
  37.              putchar(letters[x+2]);
  38.              break;
  39.     default: if (j>=5) j-=5,putchar(letters[x+1]);
  40.              for(;j;j--) putchar(letters[x]);
  41.   }
  42.   return 0;
  43. }
  44.  
  45. -- 
  46. Walter Misar                                | It is impossible to enjoy
  47. misar@rbg.informatik.th-darmstadt.de        | idling thoroughly unless
  48.                                             | one has plenty of work to do.
  49.