Converting Decimal Number lying between 1 to 3999 to Roman Numerals in C++



In this tutorial, we will be discussing a program to convert decimal number lying between 1 to 3999 to roman numerals.

For this we will be provided with a random integer. Our task is to convert the given number into its roman numeral equivalent.

Example

 Live Demo

#include <bits/stdc++.h> using namespace std; //converting decimal to roman numeral int printRoman(int number){    int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};    string sym[] =    {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};    int i=12;    while(number>0){       int div = number/num[i];       number = number%num[i];       while(div--){          cout<<sym[i];       }       i--;    } } int main(){    int number = 3949;    printRoman(number);    return 0; }

Output

MMMCMXLIX
Updated on: 2020-01-29T07:45:23+05:30

421 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements