Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!umcp-cs!chris
From: chris@umcp-cs.UUCP (Chris Torek)
Newsgroups: net.sources
Subject: (Re LBL) a routine to convert to Roman numerals
Message-ID: <741@umcp-cs.UUCP>
Date: Fri, 5-Jul-85 10:26:50 EDT
Article-I.D.: umcp-cs.741
Posted: Fri Jul  5 10:26:50 1985
Date-Received: Sun, 7-Jul-85 04:42:15 EDT
References: <587@hwcs.UUCP>
Organization: U of Maryland, Computer Science Dept., College Park, MD
Lines: 41

I noticed while scanning through the source to lbl that it converts
things to Roman.  Here is a rather clever way to do the same, due
to Knuth, converted to cryptic C code.

/*
 * Print a roman numeral representation of the positive integer 'n'
 * (negative numbers produce no output).
 */
pr_roman (n)
register int n;
{
    register int    u,
                    v;
    register char  *p,
                   *q;

    p = "m\2d\5c\2l\5x\2v\5i";
    v = 1000;
    for (;;) {
	while (n >= v)
	    putchar (*p), n -= v;
	if (n <= 0)
	    return;
	q = p + 1;
	u = v / *q;
	if (*q == 2)
	    u /= *(q += 2);
	if (n + u >= v) {
	    putchar (*++q);
	    n += u;
	}
	else {
	    p++;
	    v /= *p++;
	}
    }
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland