#include<stdio.h>
#include<conio.h>
int main()
{
long int number;
int j;
clrscr();
printf("\n\t\tPROGRAM TO DISPLAY INTEGER BELOW 2000 TO A ROMAN NUMERAL");
printf("\n\n Enter a positive integer below 2000 : ");
scanf("%ld",&number);
printf("\n Roman number for the entered number %ld = ",number);
if(number <= 0 || number > 2000)
{
printf("Invalid number");
return 0;
}
while(number != 0)
{
if(number >= 1000)
{
for(j=0;j<number/1000;j++)
printf("%c",'M');
number = number - (number/1000) * 1000;
}
else if(number >=500)
{
if(number < (500 + 4 * 100))
{
for(j=0;j<number/500;j++)
printf("%c",'D');
number = number - (number/500) * 500;
}
else
{
printf("%c%c",'C','M');
number = number - (1000-100);
}
}
else if(number >=100)
{
if(number < (100 + 3 * 100))
{
for(j=0;j<number/100;j++)
printf("%c",'C');
number = number - (number/100) * 100;
}
else
{
printf("%c%c",'C','D');
number = number - (500-100);
}
}
else if(number >=50)
{
if(number < (50 + 4 * 10))
{
for(j=0;j<number/50;j++)
printf("%c",'L');
number = number - (number/50) * 50;
}
else
{
printf("%c%c",'X','C');
number = number - (100-10);
}
}
else if(number >=10)
{
if(number < (10 + 3 * 10))
{
for(j=0;j<number/10;j++)
printf("%c",'X');
number = number - (number/10) * 10;
}
else
{
printf("%c%c",'X','L');
number = number - (50-10);
}
}
else if(number >=5)
{
if(number < (5 + 4 * 1))
{
for(j=0;j<number/5;j++)
printf("%c",'V');
number = number - (number/5) * 5;
}
else
{
printf("%c%c",'I','X');
number = number - (10-1);
}
}
else if(number >=1)
{
if(number < 4)
{
for(j=0;j<number/1;j++)
printf("%c",'I');
number = number - (number/1) * 1;
}
else
{
printf("%c%c",'I','V');
number = number - (5-1);
}
}
}
getch();
return 0;
}