Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

C++ program to display the given number in roman number

YASH PAL, 31 July 202422 August 2024

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 the given number in 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
coding problems cpp

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes