From 475e52b744d4435aac04b15a3224b4a3f1f82eb1 Mon Sep 17 00:00:00 2001 From: ShreyaShukla03 <93048997+ShreyaShukla03@users.noreply.github.com> Date: Mon, 16 Oct 2023 23:01:19 +0530 Subject: [PATCH] Create NumbertoRoman.cpp The program converts a given integer to roman. --- Coding/NumbertoRoman.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Coding/NumbertoRoman.cpp diff --git a/Coding/NumbertoRoman.cpp b/Coding/NumbertoRoman.cpp new file mode 100644 index 00000000..5ff8e51e --- /dev/null +++ b/Coding/NumbertoRoman.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; + string intToRoman(int num) { + mapmp; + mp[1]="I"; + mp[4]="IV"; + mp[5]="V"; + mp[9]="IX"; + mp[10]="X"; + mp[40]="XL"; + mp[50]="L"; + mp[90]="XC"; + mp[100]="C"; + mp[400]="CD"; + mp[500]="D"; + mp[900]="CM"; + mp[1000]="M"; + int len=0,z=num; + while(z!=0){ + z/=10; + len++; + } + z=num; + string ans=""; + for(int i=len-1;i>=0;i--){ + int div=pow(10,i); + int req=z/div; + // cout<<"z "<=5){ + ans+=mp[5]; + req-=5; + } + if(div==10&&req>=5){ + ans+=mp[50]; + req-=5; + } + if(div==100&&req>=5){ + ans+=mp[500]; + req-=5; + } + while(req--)ans+=mp[div]; + } + z=z-val; + } + + return ans; + } +int main() { + string z=intToRoman(1994); + cout<<"The required conversion of Integer to Roman "<