Contact Learn C
Copy Program Share Program

Program 97:Convert Roman to Decimal

Program 97:
#include<stdio.h> 
#include<string.h> 
#include<stdlib.h> 
int main() 
{ 
int a[100],len,i,j,k; 
char rom[100];
printf("Enter the Roman Numeral:\n"); 
scanf("%s",rom); 
len=strlen(rom); 
for(i=0; i<len; i++) 
    {
     if(rom[i]=='I') 
     a[i]=1; 
     else if(rom[i]=='V') 
     a[i]=5; 
     else if(rom[i]=='X') 
     a[i]=10; 
     else if(rom[i]=='L') 
     a[i]=50; 
     else if(rom[i]=='C') 
     a[i]=100; 
     else if(rom[i]=='D') 
     a[i]=500; 
     else if(rom[i]=='M') 
     a[i]=1000; 
     else 
     { 
     printf("\nInvalid Value"); 
     exit(0); 
     } 
 } 
     k=a[len-1]; 
     for(i=len-1; i>0; i--) 
    { 
     if(a[i]>a[i-1]) 
     k=k-a[i-1]; 
     else if(a[i]==a[i-1] || a[i]<a[i-1]) 
     k=k+a[i-1]; 
     } 
     printf("Its Decimal Equivalent is:"); 
     printf("%d\n",k); 
     return 0;
 }
Explanation:

//Coming Soon...

Output:

Convert Roman to Decimal

3 comments:

  1. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. convert money online

    ReplyDelete
  2. When you are converting a currency, you are managing two unique instruments, which are esteemed against one another. convert money calculator

    ReplyDelete
  3. Additionally, numerous a monetary investigators have found that Forex investing is a profoundly gainful and worthwhile alternative when contrasted with the other future and financial exchanges speculations. top forex broker in South African

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide