Read a roman number and convert that into decimal. For such a problem we have to find a suitable solution. we need to write a method to read the Roman number and a converter. there is a common patterns in Roman numbers and find a solution to convert.
For example , " III "means 1+1+1=3 , " V " means 5 " IV " means 4 how ?
let see , First read string and check from back to front .so now we have first " V " and " I " .now check last character is grater other one then " - " operator else " + "operator ( if V > I then 5 - 1 = 4 )
For example , " III "means 1+1+1=3 , " V " means 5 " IV " means 4 how ?
let see , First read string and check from back to front .so now we have first " V " and " I " .now check last character is grater other one then " - " operator else " + "operator ( if V > I then 5 - 1 = 4 )
Example :
" IX " "1" "10" this mean 10 > 1 then 10 -1 =9.
" XIV " "10""1""5" this mean 4 >1 so 5-1 = 4 and renaming 10 ==>10+4 = 14
Roman To Decimal
When you run the program, the output will be:
Enter roman number you want to convert
Command End to stop entering
i
I is equal to 1
iv
IV is equal to 4
ix
IX is equal to 9
xii
XII is equal to 12
xiv
XIV is equal to 14
c
C is equal to 100
xc
XC is equal to 90
m
M is equal to 1000
cm
CM is equal to 900
xm
XM is equal to 990
End
إرسال تعليق
Thank you for vising