Convert Arabic numerals to Roman numerals
Convert Arabic numerals greater than 0 and less than 1000 to Roman numerals. The correspondence between Arabic numerals and Roman numerals is as follows:
* Problem analysis and Algorithm Design
The corresponding relationship between Arabic numerals and Roman numerals is given in the question. The digital conversion in the question is actually table-based translation. The Hundred, ten, and single digits of an integer are decomposed from the integer in turn, and the corresponding rows in the table are searched and the corresponding characters are output.
* Program and Program Design
# Include <stdio. h>
Void main ()
{
Static char * A [] [10] = {"", "I", "II", "III", "IV", "V", "Vi ", "VII", "VIII", "IX"
"", "X", "XX", "XXX", "XL", "L", "lx", "LXX", "LXXX", "Xcc ",
"", "C", "cc", "CCC", "cd", "D", "DC", "DCC", "DCCC", "cm"
};/* Create a comparison table */
Int N, T, I, m;
Printf ("Please enter number :");
Scanf ("% d", & N);/* enter an integer */
Printf ("% d =", N );
For (m = 0, I = 1000; m <3; m ++, I/= 10)
{
T = (N % I)/(I/10);/* take the numbers from high to low */
Printf ("% s", a [2-M] [T]);/* translate and output through the comparison table */
}
Printf ("N ");
}
* Running result
1. Please enter number: 863
863 = dccclxiii
2. Please enter number: 256
256 = cclvi
3. Please enter number: 355
355 = ccclv
4. Please enter number: 522
522 = dxxii
5. Please enter number: 15
15 = XV
* Questions
Enter a positive integer n to generate a corresponding English number string and output it. For example:
1 One 2 two 3 three
10 ten 11 eleven
135 one hundred thirty five