home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
- Newsgroups: comp.lang.c
- Subject: Re: Roman Numerals
- Date: 26 Jan 1993 19:35:02 GMT
- Organization: TH Darmstadt
- Lines: 37
- Distribution: world
- Message-ID: <1k43p6INNjr3@rs2.hrz.th-darmstadt.de>
- References: <damatt01.728068722@starbase.spd.louisville.edu>
- NNTP-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
-
- In article <damatt01.728068722@starbase.spd.louisville.edu>, damatt01@starbase.spd.louisville.edu (David A. Mattingly) writes:
- >
- > Does anyone know of an integer-to-Roman-numeral converter? I know I saw one in
- > a collection of utilities, maybe on simtel20...
-
- Get yourself intercal :)
-
- In C this routine should do:
-
- #include <stdio.h>
-
- int roman(int num)
- { static char *letters="IVXLCDMA";
- static int x=0;
- int j;
-
- if (num<=0 || num>=4000) return -1;
- x+=2;
- if (num>=10) roman(num/10);
- x-=2;
- switch(j=num%10)
- { case 4 : putchar(letters[x]);
- putchar(letters[x+1]);
- break;
- case 9 : putchar(letters[x]);
- putchar(letters[x+2]);
- break;
- default: if (j>=5) j-=5,putchar(letters[x+1]);
- for(;j;j--) putchar(letters[x]);
- }
- return 0;
- }
-
- --
- Walter Misar | It is impossible to enjoy
- misar@rbg.informatik.th-darmstadt.de | idling thoroughly unless
- | one has plenty of work to do.
-