Skip to content
Programming101
Programmingoneonone

Learn everything about programming

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

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
C++ Programming Tutorials coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes