Contact Learn C
Copy

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

9 comments:

  1. Each part of the crypto trading bot (signal generator, risk allocation and execution) must have its own algorithm and optimization processes. Each component is integral to executing trades profitably Crypto bot .

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. FinTech enhance connection directly with clients with the launch of Crowdfunding Platforms. It allows local business, musicians, charities and also entrepreneurs to get support without raising money from standard capitalists.

    B2B Fintech

    ReplyDelete
  4. Hi,
    The roman number 'CM' is getting converted to 32448 whereas the expected output is 900. Also, "MCMXCIV" is getting converted as 844487368 when the expected output is 1994

    ReplyDelete
  5. It is nice to read such high-quality content. It is a good article that discusses the topic at hand quite well. I am looking forward to read more articles from your site. Keep up the good work.

    Astrologer in Boston,
    Astrologer in Texas,
    Astrologer in Texas,
    Palm Reader In Texas,

    ReplyDelete
  6. I like what you guys are up too. Such smart work and reporting! Carry on the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my web site :)

    Vashikaran Specialist,
    Expert Astrologer in Armenia,
    Best Astrologer in Bahamas,
    Top Astrologer in Bahrain,
    Best Astrologer in Barbados,

    ReplyDelete
  7. This is very interesting, You are a very skilled blogger. I’ve joined your feed and look forward to seeking more of your excellent post. Also, I’ve shared your website in my social networks!
    About Cricbuzz,
    Cricket News Twitter,

    ReplyDelete
  8. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
    Astrologer In Usa,
    Black Magic Removal In Texas,
    Vashikaran Mantra in Hindi,

    ReplyDelete

Donate

Download App and Learn when ever you want

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