➽ Program:-
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int
main()
{
int a[100], len, x, y, z;
char roman[100];
printf("Enter the Roman Numeral:
");
scanf("%s", 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
{
printf("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];
}
printf("Decimal Value is: ");
printf("%d",z);
return 0;
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.