Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
Advertisements