Arabic numerals into Roman numerals

Source: Internet
Author: User
Tags first string

tag: dos c language

<Span style = "font-size: 18px;" >#include <stdio. h> # include <stdlib. h> # include <string. h> # define rows 4 # define Cols 4int Nums [rows] [Cols] = {900,500,400,100,}, {}, {90, 50,}, {9, 5, 4, 1 }}; char * ROMs [rows] [Cols] = {"M", "M" },{ "cm ", "D", "cd", "C" },{ "XC", "L", "XL", "x" },{ "IX", "V ", "IV", "I" }};/* Two-dimensional array pointer */void judge (INT num) // determine whether the input number is in the specified range {If (Num <1 | num> 9999) {printf ("Please input the right n Umber! \ N "); exit (0) ;}} void trans (INT num, char Roman []) // convert Arabic numerals into Roman numerals {int I, J; roman [0] = '\ 0';/* this step is necessary, because the strcat function will find the' \ 0' of the first string ', after finding it, remove it and copy the string. If it is not initialized, the content of the second string cannot be copied at the end of the first */for (I = 0; I <rows; I ++) {for (j = 0; j <Cols; j ++) {While (Num> = Nums [I] [J]) /* set to loop */{printf ("% s \ n", Roman); strcat (Roman, ROMs [I] [J]); num-= Nums [I] [J] ;}}} void main (INT argc, char * argv []) {char Roman [25]; int low, high; if (argc <2) {printf ("Please input numb Er! \ N "); exit (0);} low = high = atoi (argv [1]); // The atoi function is to convert the string to an integer judge (low ); if (argc> 2) {high = atoi (argv [2]); // This program can only successfully receive three strings judge (high); If (low> high) {LOW = high; high = atoi (argv [1]) ;}} else low = 1; for (; low <= high; low ++) {TRANS (low, roman); printf ("% 4D = % s \ n", low, Roman) ;}</span>
in this program, enter the file path and two strings (which will be converted to an integer) in the DOS command status ), it will output all the Arabic numerals between two integers.

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.