# convert decimal to roman

Page 1 of 1

## 4 Replies - 16125 Views - Last Post: 28 December 2006 - 04:08 AMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=22405&amp;s=83ddbc3050c434e86d06c95fa8a9101e&md5check=' + ipb.vars['secure_hash'], cur_rating: 1, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 santoshbb

Reputation: 0
• Posts: 2
• Joined: 12-December 06

# convert decimal to roman

Posted 27 December 2006 - 03:16 AM

M=1000 | D=500 | C=100 | L=50 | X=10 | V=5 | I=1
MDCLXVI = 1000 + 500 + 100 + 50 + 10 + 5 + 1 = 1666.

but i need to convert the given integer in the form of 1000,500,100,50,10,5 and 1s

Is This A Good Question/Topic? 0

## Replies To: convert decimal to roman

### #2 dorknexus

Reputation: 1256
• Posts: 4,618
• Joined: 02-May 04

## Re: convert decimal to roman

Posted 27 December 2006 - 04:10 AM

can you show us what code you've attempted thus far?

### #3 may4life

Reputation: 1
• Posts: 23
• Joined: 05-November 06

## Re: convert decimal to roman

Posted 27 December 2006 - 10:17 AM

first of all you need to figure out which is the greatest value a roman number can have. As you mention it is 1000 (M).
If your number is >= 1000, you will then need to display how many thousands it has, each time subtracting 1000 from your original number.
i.e
```if (number >= 1000)
{
cout << "M";
number-=1000;
}

```

Then, with the same logic, use the display-subtract method for the number being >= to 500, then >= 100, then >=50 and so on until your number reaches 0.
Try it out and post some code and we'll all definitely help you out here.

This post has been edited by may4life: 27 December 2006 - 10:18 AM

### #4 may4life

Reputation: 1
• Posts: 23
• Joined: 05-November 06

## Re: convert decimal to roman

Posted 28 December 2006 - 03:16 AM

The next step would be to contain this code in a loop until the number is no longer in that field.
i.e
```while (number >= 1000)
{
if (number >= 1000)
{
cout << "M";
number-=1000;
}
}

```

After this you implement for 500, 100, 50 and so on until you get to the code
```while (number >= 1)
{
if (number >= 1)
{
cout << "I";
number-=1;
}
}

```

And that's it!! Decimal to Roman in no time. This is one way of doing it, im sure there are loads of other ways if you sit down n think a bit

This post has been edited by may4life: 28 December 2006 - 03:17 AM

### #5 m2s87

• D.I.C Regular

Reputation: 21
• Posts: 390
• Joined: 28-November 06

## Re: convert decimal to roman

Posted 28 December 2006 - 04:08 AM

Quote

And that's it!! Decimal to Roman in no time. This is one way of doing it, im sure there are loads of other ways if you sit down n think a bit

Well 1 way to do this, is use my c++ snippet that i added yesterday.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }