➽ Program:-
#include<iostream>
#include<string.h>
#include<stdlib.h>
using
namespace std;
int
main()
{
int a[100], len, x, y, z;
char roman[100];
cout << "Enter the Roman
Numeral: ";
cin >> roman;
len = strlen(roman);
for(x=0; x<len; x++)
{
if(roman[x] == 'I')
a[x] = 1;
else if(roman[x] == 'V')
a[x] = 5;
else if(roman[x] == 'X')
a[x] = 10;
else if(roman[x] == 'L')
a[x] = 50;
else if(roman[x] == 'C')
a[x] = 100;
else if(roman[x] == 'D')
a[x] = 500;
else if(roman[x] == 'M')
a[x] = 1000;
else
{
cout << "Invalid
Value";
}
}
z = a[len-1];
for(x=len-1; x>0; x--)
{
if(a[x] > a[x-1])
z = z - a[x-1];
else if(a[x]==a[x-1] || a[x]<a[x-1])
z = z + a[x-1];
}
cout << "Decimal Value is:
";
cout << z;
return 0;
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.