Answer to Question #9064 in MatLAB | Mathematica | MathCAD | Maple for sara
. Write a script/function that converts a Roman numeral to its decimal equivalent.
There are two distinct situations that you might design your program for:
a. The "old" style where the order of the symbols does not matter. In this case, IX and XI both mean 10 + 1 or 11. You should be able to handle the following conversion table:
b. The "new" style where the order of the symbols does matter. For example, IX is 9 (10 - 1), XC is 90 (100 - 10). The conversion table given above still holds and you may assume for this case that the only instances of "order" you will encounter are
IV (4), IX (9), XL (40), XC (90), CD (400) and CM (900)
The function input will be useful here. The format
>> str = input('Roman numeral: ','s')
will provide a way to get the Roman number into your program as a string. It would be a good idea to try case a. first.