//Decimal to Roman
#include <stdio.h>
#include <conio.h>
void
main()
{
int i,j,dig,len,k;
char
*ch[][2] = {"I",
"V","X","L","C","D","M","Z"};
char n[5];
clrscr();
printf("\n\tEnter a
integer no : ");
gets(n);
printf("\n\t\tDecimal
%s equivalent Roman = ",n);
len=strlen(n);
for(i=0;i<len;i++)
{
dig=n[i]-'0';
k=len-(i+1);
if(dig<=3)
{
for(j=1;j<=dig;j++)
{
printf("%s",ch[k][0]);
}
}
else
if(dig<=4)
{
printf("%s%s",ch[k][0],ch[k][1]);
}
else
if(dig==5)
{
printf("%s%s",ch[k][1]);
}
else
if(dig<=8)
{
printf("%s%s",ch[k][1]);
for(j=6;j<=dig;j++)
{
printf("%s",ch[k][0]);
}
}
else
if(dig==9)
{
printf("%s%s",ch[k][0],ch[k+1][0]);
}
}
getch();
}
No comments:
Post a Comment