Convert Arabic numerals to Roman numerals

Source: Internet
Author: User
Tags comparison table
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.