answersLogoWhite

0

x=input('Enter the roman numeral: ','s');

l=length(x);

for(i=1:l)

if(x(i)=='I')

a(i)=1;

elseif(x(i)=='V')

a(i)=5;

elseif(x(i)=='X')

a(i)=10;

elseif(x(i)=='L')

a(i)=50;

elseif(x(i)=='C')

a(i)=100;

elseif(x(i)=='D')

a(i)=500;

elseif(x(i)=='M')

a(i)=1000;

else

disp('Not a valid entry');

end

end

d=a(l);

for(i=l:-1:2)

if(a(i)>a(i-1))

d=d-a(i-1);

elseif(a(i)==a(i-1) a(i)<a(i-1))

d=d+a(i-1);

end

end

disp('The decimal equivalent is: ');

disp(d);

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: How do you convert a roman numeral into decimal using matlab?
Write your answer...
Submit
Still have questions?
magnify glass
imp