1. ## Addition of Roman numbers

How to write a program ,in C,which inputs two numbers specified in Roman numerals and outputs the sum of these two numbers in Roman numerals,no matter with capitals or not?
im interested in Using arrays to store the input numbers (character sequences) and utilizing functions to do error checking and array-processing

example
input:CCCXi+CxXViIi
output:CDXXXIX

input: DCCXiv+DccciV
output:MDXVIII

input:MLxvII+Mmiii
output:MMMLXX

Code:
```•	I =1			i =1
•	V = 5			v =5
•	X = 10		x =10
•	L = 50		l =50
•	C = 100		c = 100
•	D = 500		d = 500
•	M = 1000		m = 1000```

2. We don't do Homework.

However, you may want to post a question ON your homework, perhaps?

Or, you can post some code, along with questions ON that code.

--
Mats

3. yes,i actually wanted to ask how to do addition ,i.e converting roman number to decimal ,mcmxxxiv

4. You mean, you wanted to ask "How do I convert roman numbers to deciaml?", yes?

Basicly, you walk through the string and evaluate each letter or letter combination [e.g. IX is 9, not 11].

You may want to start with a small subset, e.g. only supporting I, V and X as inputs, and just displaying the arabic [our normal 0..9] notation of the number.

--
Mats

5. So start with a function which converts a roman number (as a string) into an integer.
Then create one which converts and integer into a roman number (as a string).

6. what about 40(XL),60(LX) or 1965(MCMVXXV),2002(MMII)

romans can be written before and after any other roman,it confuses me

7. Yes, basically if a lower number is placed before a higher number, you subtract the smaller part from the bigger. If a higher number is before a lower number, you add them.
But start small. Try to make a small parser that converts the roman numbers into integers. you could just translate all letters into their integer counterparts and add them together and worry about subtraction later.

8. > romans can be written before and after any other roman
It's not ANY, there are rules.

You have
M D C L X V I

1. Only C X I can appear to the left of something which is a higher value.

2. C can only appear before M or D,
X can only appear before C or L
I can only appear before X or V.

Which is why 1999 is MCMXCIX and not MIM

3. They're also written most significant first.

4. The prefix form only appears when you have a '4' or a '9' to encode, so 49 is XLIX (10 before 50 + 1 before 10).

5. You're not the first person to ever ask this, so try a board search.

9. conversion of roman to arabic is done,but now how should i read 2 roman numbers ,how can i get numbers in the left and in the right of +

and whats wrong with this one its just retypes what i type (conv. of arabic to roman,3digits)

Code:
```#include<stdio.h>

int main(){

int num;

scanf("&#37;d",&num);
switch(num/100){

case '1' : printf("C");
break;
case '2' : printf("CC");
break;
case '3': printf("CCC");
break;
case '4': printf("C D");
break;
case '5': printf("D");
break;
case '6': printf("DC");
break
case '7': printf("DCC");
break;
case '8': printf("DCCC");
break;
case '9': printf("CM");
break;
}

switch((num%100)/10){

case '1': printf("X");
break;
case '2': printf("XX");
break;
case '3': printf("XXX");
break;
case '4': printf("XL");
break;
case '5': printf("L");
break;
case '6': printf("LX");
break;
case '7': printf("LXX");
break;
case '8': printf("LXXX");
break;
case '9': printf("XC");
break;
}

switch(num%100){

case '1': printf("I");
break;
case '2': printf("II");
break;
case '3': printf("III");
break;
case '4': printf("IV");
break;
case '5': printf("V");
break;
case '6': printf("VI");
break;
case '7': printf("VII");
break;
case '8': printf("VIII");
break;
case '9': printf("IX");
break;
}

printf("%d",num);

return 0;

}```

10. Try case 1: rather than case '1':

11. yes you are right
but this time i get

532
DXXX532

loop does not enter last switch and output is roman and entered number

12. The reason that your solution sort of works is that you can keep up with the bigger deductions like 500 or 100, but the solution fails when it needs to deduct fives or ones.

Keeping Salems rules in mind basically translates directly into a lengthly, but plausible solution using string concatenation and successive deductions.

I'm going to assume a ceiling of 999 as you've stated before. Here's an example of what I am talking about in some pseudo-not-really-code:

Code:
```void to_roman ( unsigned long number )
{
if ( number <= 999 && number >= 1 ) {
if ( number > 899 ) {
number -= 900;
printf( "CM" );
}
if ( number > 499 ) {
number -= 500;
printf( "D" );
}
while ( number > 99 ) {
number -= 100;
printf( "C" );
}
if ( number > 89 ) {
number -= 90;
printf( "XC" );
}
// and so on ...
}
putchar( '\n' );
}```
It's that simple. Just make sure that you account for all of the possible deductions.

13. First you do something like
y = ( x / 1000 ) &#37; 10

If y is 4 or 9, then you have one of the prefix forms to deal with.
If y is 1 to 3, then output that many of the appropriate 'unit' symbol
if y is 5 to 8, then output the appropriate 'five' symbol, and y-5 of the 'unit' symbol