rjnoe@ihlts.UUCP (Roger Noe @ N41:48:31, W88:07:13) (02/06/84)
/* ROMAN: converts Arabic notation decimal numbers to Roman. */ /* Input is command-line parameter, ASCII string for decimal integer. Up to seven characters, between '0' and '9'. */ /* Output is on standard output, consisting of characters seen below. */ #include <stdio.h> char one[] = "ixcmXCM"; /* Lowercase letters used! */ char five[] = "vldVLD"; /* Uppercase used for numerals */ /* with bars over them. */ main(argc, argv) int argc; char *argv[]; { register short i, j, k; char number[8]; char *cp; if(argc < 2) { fprintf(stderr, "Usage: %s <arabic>\n", argv[0]); exit(1); } for(i=0, cp=argv[1]; i<8 && *cp != '\0'; i++, cp++) if(*cp >= '0' && *cp <= '9') number[i] = *cp; else { fprintf(stderr, "Illegal character: %c\n", *cp); exit(2); } if(i == 8) { fprintf(stderr, "Parameter out of range\n"); exit(2); } cp=number; while(i) { j = *cp++ - '0'; if(--i == 6) for(k=0; k<j; k++) putchar(one[6]); else switch(j) { case 9: putchar(one[i]); putchar(one[i+1]); break; case 4: putchar(one[i]); putchar(five[i]); break; default: if(j >= 5) { putchar(five[i]); j -= 5; } for(k=0; k<j; k++) putchar(one[i]); break; } } putchar('\n'); }