Roman numers to decimal

  • File name: Roman to decimal
  • Size: 689 b
yes /


Program that converts a roman numeral such as "XVIII" to decimal "33" by a function with a string with the roman numer.

We assume that can be put four equal characters instead of subtracting, ie will IIII instead of IV. Thus, it is sum values depending on which character is concerned.

#include <stdio.h>
#include <string.h>

int rom2dec(char s[]){
    int i,r=0,valor;

            case 'I':valor=1;break;
            case 'V':valor=5;break;
            case 'X':valor=10;break;
            case 'L':valor=50;break;
            case 'C':valor=100;break;
            case 'D':valor=500;break;
            case 'M':valor=1000;break;
            default: break;
    return r;

int main(){
    char cad[20];
    int decimal;

    printf("Escribe un número romano\n:");
    printf("El valor decimal de %s es %d",cad,decimal);

    return 0;


More exercises in

No ratings yet - be the first to rate this.

Add a comment

You're using an AdBlock like software. Disable it to allow submit.