djfish's studio

12/30/2008

THE C PRIMER roman numerals

different numberals have influenced the course of mathematic.
/*print an Arabic number in Roman numberals*/
roman(arabic)
int arabic;
{
arabic =romanize(arabic, 1000, 'M');
arabic =romanize(arabic, 500, 'D');

arabic =romanize(arabic, 100, 'C');

arabic =romanize(arabic, 50, 'L');

arabic =romanize(arabic, 10, 'X');

arabic =romanize(arabic, 5, 'V');
romanize(arabic, 1, 'I');
putchar('\n');

}

/* Print the character c as many times as here are j's in the number i,then return i minus the j's.*/
romanize(i,j,c)
char c;
int i,j;
{
while(i>=j)
{
putchar(c);
i=i-j;
}
return(i);
}

No comments:

Post a Comment