So do you want to do this in C (which is the code you posted) or C++?
yes!! c++..sorry for some wrong doing i am doing that only says to you that i am only a beginner in terms of this area..or forum..
I never understood the massive confusion that surrounds Roman numerals and using them. Proper Roman numerals are always arranged from greatest to least so conversion is simply done by computing from left to right. If a number or group of numbers is smaller than its neighbor then you have to subtract the left thing from the right thing in the sum. There is no standardization. XXCIII is as correct as LXXXIII is for 83, so sanitizing is kind of pointless.Ordinary Numbers = Roman Numerals
1=I
5=V
10=X
50=L
100=C
500=D
100=M
But yes, your point about non-standardization is spot on.Ordinary Numbers = Roman Numerals
1=I
5=V
10=X
50=L
100=C
500=D
1000=M
yeahh.it is easy in terms of coverting it..ahmmm plase mr.kindly my actual problem on the very beginning of the first page...thank you hope you understand what i want to say..thank you/
Step 1: Is the input greater than the largest Roman numeral?my problem is this...please help. i need a algorithm and solution,,
If not, then the very first numeral is not 'M'. If so, then the very first numeral is 'M'.
mr.andrew the code that you posted i am not familiar on that kind of code..like i said i am only familiar in a header files..stdio.h and conio.h.
and i ahm only using the (int)as a variable declaration..
i i am only familiar with a code ending in getch; and }..
no! my input data must:
"Iput a number to be converted:"
and as i result i will output it in form of roman numeral.
my problem is to convert the number to a roman numeral..with a no.input of a 3000 capacity.
Yes!
Step 1: Is the input greater than the largest Roman numeral? <----- Input number to be converted!
If not, then the very first numeral is not 'M'. If so, then the very first numeral is 'M'. <----- Output in the form of a Roman numeral!
If numbers in Roman numerals are arranged from greatest to least it stands to reason that writing Roman numerals is just about taking the biggest chunks you can out of numbers.
Find out which of the biggest denominations you can start with and write it. Usually this means you can concentrate on each place value at once.
1984 is more than 1000. Write the letter M. Convert 984 next.
984 is less than 1000 but more than 500 so write D. Convert 484 next.
484 is less than 500 but more than one hundred. If we stick to the plan, we can convert a single place value. 4 Cs make up 400. Convert 84.
80 is more than 50, so write L, then convert 34.
30 is XXX. Convert 4.
Now we come to single digits which you should probably just have saved for lookup. 4 is IV.
You might end up with loooong numbers, but this is why we use Arabic.
i cant get your point mr.matticus..am for us to communicate well..refer to my example..
when i input: 1000
the output must be: M
if i input:3000
then the output is:MMM
if i input 1
the output must be I
and i input 9
the out put must be IX..
_when ever i input..it mus output it equivalent roman numerals..my point is what formula i will do..when it comes in 9,111,11,3,4,1002,etc,,....
if only the numbers to be input is on the chart. it is easy..because i will only write the formula
example//
if(n(variable declaration as input value)==1)
prinf(The roman is: I);
else if(n==1000)
printf("The Roman is:M");
but how if the input is 9??
how i output it as IX??what formula i will do to ouput it??
do i need to ennumerate it all from 1 to 3000??
Well the usual standard is to have no more than than 3 consecutive digits added, so that XXX is 30, XL is 40, LXXX is 80, and XC is 90. But that just adds a few extra steps.
It's up to the OP and his instructor whether or not to apply that standard.
Converting the other way it would make sense to allow more liberal ordering.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
WhiteFlags gave you really good advice, much better than mine. You should read that thoroughly, it should answer your question.
yes..i thought that your getting what i mean whiteflags??then what kind of operators i will use..??when i write a algorithm flowchart and solution..can you give a example code??when converting 9??i will use it as a guidelines..