answersLogoWhite

0

There is a very good article on performing conversions from integers to roman numerals here: http://www.faqs.org/docs/javap/c9/ex-9-3-answer.html The article includes the full source code necessary to implement this solution on your own.

User Avatar

Wiki User

∙ 17y ago
User Avatar

What else can I help you with?

Continue Learning about Engineering

What is c program of roman numbers?

The following code demonstrates how to convert decimal numerals to Roman numerals in the range 1 to 3999. Although there are some little-known conventions that allow numbers in excess of 3999 to be notated using special symbols, annotations and spacings to mulitply smaller numbers to produce larger numbers, the accepted convention states that no individual symbol may be repeated more than 3 times in succession (thus MMMM (4000) would not be allowed). Also, although there is nothing intrinsically wrong with using numerals such as IC to mean 99, the accepted convention with subtractive pairs states that I may only precede X and V, X may only precede C and L, and C may only precede M and D, while D, L and V may not be used as a prefix for any subtractive pair (thus ruling out VL for 45). Using the accepted convention makes it that much easier to code the conversion, however it is only a convention and there is no actual standard with regards Roman numerals. The accepted convention is simply the one that the majority of people will be most familiar with. The only time we really break from convention is when designing clock faces, as using the non-conventional numeral IIII (4) is more aesthetically pleasing than IV. It not only gives a sense of balance to the VIII on the other side, but it also divides the clock face into three distinct regions, where only I appears in the first region (1, 2, 3 and 4), V appears in the second region (5, 6, 7 and 8) and X in the last region (9, 10, 11 and 12). #include<iostream> #include<string> std::string roman(unsigned int dec) { std::string roman; if( dec && dec<4000 ) { while(dec>=1000) { roman+="M"; dec-=1000; } if(dec>=900) { roman+="CM"; dec-=900; } if(dec>=500) { roman+="D"; dec-=500; } if(dec>=400) { roman+="CD"; dec-=400; } while(dec>=100) { roman+="C"; dec-=100; } if(dec>=90) { roman+="XC"; dec-=90; } if(dec>=50) { roman+="L"; dec-=50; } if(dec>=40) { roman+="XL"; dec-=40; } while(dec>=10) { roman+="X"; dec-=10; } if(dec>=9) { roman+="IX"; dec-=9; } if(dec>=5) { roman+="V"; dec-=5; } if(dec>=4) { roman+="IV"; dec-=4; } while(dec--) {roman+="I"; } } return(roman); } int main() { for(unsigned int i=1; i<4000; ++i ) std::cout<<i<<" = "<<roman(i).c_str()<<std::endl; return(0); } Output: 1 = I 2 = II 3 = III 4 = IV 5 = V 6 = VI ... 3997 = MMMCMXCVII 3998 = MMMCMXCVIII 3999 = MMMCMXCIX


Why do computers work with bits rather than decimal digits?

Ever wonder what the real numbers are? Numbers are artificial things invented by human, and the same applied to computers. So, the inventors of computers storing human readable numbers (decimal, Roman numerals, etc...) as computer readable numbers (binary). Binary fit very well with the electrical pulses (on and off, as 1 and 0)


Four examples of Roman technology?

The roman technologies are: nine aqueducts to provide water for the roman people, amphitheaters, the Colosseum, and the romans greatest achievement was the sewer system.


What are the roman achievements in engineering?

hi


Whats the HTML code for roman numerals for a webpage?

To write a Roman Numeral you simply type in the letters in the text (4) IV. if you want an ordered list using Roman Numerals use the following list tags: A basic list using bullets (small black circles) starts with the tag and each item listed with the tags item one item two (end list) will result in Item one item two For a Ordered numbered listinstead of a bullet list use (ordered list) instead of (unordered list) to start. for example item oneitem two This will result in: # item one # item two For a Roman Numeral list you have to use the Type= attribute with the value "I" (capital i) inside the list start tag as follows, This will give you Roman Numerals For example: First Roman Numeral Item ISecond Roman Numeral Item II Third Roman Numeral  Item III The capital "I" will give you the Roman Numerals in capitals. If you use a lower case "i" the Roman Numerals will all be in lower case.