News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Display roman equivalent for a given number

Started by thiruvasagamani, Sep 22, 2008, 12:16 PM

Previous topic - Next topic

thiruvasagamani

 Display roman equivalent for a given number

#include <stdio.h>
#include <conio.h>

void roman( int n)
{
while( n >= 1000)
{
printf(" M ");
n = n - 1000;
}
while( n >= 900)
{
printf( " CM");
n = n - 900;
}
while( n >= 500)
{
printf(" D ");
n = n - 500;
}
while( n >= 400)
{
printf( " CD ");
n = n - 400;
}
while( n >= 100)
{
printf(" C ");
n = n - 100;
}
while( n >=90)
{
printf("XC ");
n = n - 90;
}
while( n >=50)
{
printf(" L ");
n = n - 50;
}
while( n >= 40)
{
printf(" XL ");
n = n - 40;
}
while( n >= 10)
{
printf(" X ");
n = n - 10;
}
while( n >= 9)
{
printf(" IX ");
n = n - 9;
}
while( n >= 5)
{
printf(" V ");
n = n - 5;
}
while( n >= 4)
{
printf(" IV ");
n = n - 4;
}
while( n >= 1)
{
printf(" I ");
n = n - 1;
}
}

main()
{
int n;
void roman( int n);
printf(" enter any value");
scanf("%d",&n);
clrscr();
roman(n); // display roman equivalent of 'n'
getch();
}


o/p:
If you enter 'n' value as 3878 output is MMMDCCCLXXVIII


NOTE :
Roman equivalent for important numbers

1000 ---- M
900 ---- CM
500 ---- D
400 ---- CD
100 ---- C
90 ---- XC
50 ---- L
40 ---- XL
10 ---- X
5 ---- V
4 ---- IV
1 ---- I
Thiruvasakamani Karnan