In this post, we are going to write a C++ program to display the given number in roman numbers. user will enter a number between 1 to 999. and the program will print the value of that number in the roman number.
C++ program to display numbers in roman.
#include<iostream>
#include<conio.h>
int main()
{
int y,h,t,u,res;
std::cout<<"Enter any number b/w 1 - 999 = ";
std::cin>>y;
h = y/100;
res = y%100;
t = res/10;
res = res%10;
u = res/1;
std::cout<<"Roman number is = ";
switch(h)
{
case 1:
std::cout<<"c";
break;
case 2:
std::cout<<"cc";
break;
case 3:
std::cout<<"ccc";
break;
case 4:
std::cout<<"cccc";
break;
case 5:
std::cout<<"d";
break;
case 6:
std::cout<<"dc";
break;
case 7:
std::cout<<"dcc";
break;
case 8:
std::cout<<"dccc";
break;
case 9:
std::cout<<"dcccc";
break;
}
switch(t)
{
case 1:
std::cout<<"x";
break;
case 2:
std::cout<<"xx";
break;
case 3:
std::cout<<"xxx";
break;
case 4:
std::cout<<"xxxx";
break;
case 5:
std::cout<<"I";
break;
case 6:
std::cout<<"Ix";
break;
case 7:
std::cout<<"Ixx";
break;
case 8:
std::cout<<"Ixxx";
break;
case 9:
std::cout<<"Ixxxx";
break;
}
switch(u)
{
case 1:
std::cout<<"i";
break;
case 2:
std::cout<<"ii";
break;
case 3:
std::cout<<"iii";
break;
case 4:
std::cout<<"iv";
break;
case 5:
std::cout<<"v";
break;
case 6:
std::cout<<"vi";
break;
case 7:
std::cout<<"vii";
break;
case 8:
std::cout<<"viii";
break;
case 9:
std::cout<<"ix";
break;
}
return 0;
}
Output
Enter any number b/w 1 - 999 = 364 Roman number is = ccclxiv