Hello My dear friends
Let Us contribute best C algorithms for various tasks which we have encounterd with till now,
Code should be both size and time optimized, Which explores the best features of C. I am giving one and will as i encounters
Roman Letters
The following program will help you to improve your programming skill. The following program converts the Arabic numbers to Roman numbers.
void InRoman( int n ) /* converts arabic to roman */
{
int i, v[ ] = { 1, 4, 5, 9, 10, 40, 50, 90, 100,400, 500, 900, 1000, 9999 };
char *r[ ] = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C","CD", "D", "CM", "M" };
while ( n )
{
for( i=0 ; v[i]<=n ;++i );
--i;
n -= v[i];
printf( "%s", r[i] );
}
} /*--InRoman( )----------*/
int main( void )
{
int n;
printf( "Enter the Arabic number: " );
scanf( "%d", &n );
printf( "In Roman, " );
InRoman( n );
return(0);
} /*--main( )---------*/
Note
The above program works fine upto 4999, because for 5000 we have V. In ANSI C, we can’t get V. It can be done with Turbo C(DOS programming) by changing character set with int 10h.