On 27 Sep 2006 14:33:42 -0700, "NightCrawler" <mu*********@gmail.com>

wrote:

>Hi everybody i need code for converting integer no to roman i.i

1->I,5->V n so on....

#include <stdio.h>

const char *roman_digits[] =

{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

const char *roman_tens[] =

{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};

const char *roman_hundreds[] =

{"", "C", "CC", "CCC", "CD", "D", "DX", "DXX", "DXX", "CM"};

const char *roman_thousands[] =

{"", "M"};

/* not really necessary */

void empty_keyb_buffer(void) { while (getchar()!='\n') ; }

int main()

{

int n, num_is_ok=0, digits, tens, hundreds, thousands;

while (!num_is_ok) {

printf("insert a number between 0 and 1999: ");

scanf("%d", &n);

empty_keyb_buffer();

num_is_ok=(n>=0)&&(n<=1999);

}

thousands=n/1000;

hundreds=(n%1000)/100;

tens=(n%100)/10;

digits=n%10;

printf("Roman equivalent: %s%s%s%s\n",

roman_thousands[thousands],

roman_hundreds[hundreds],

roman_tens[tens],

roman_digits[digits]);

return 0;

}