locked
A program in C to convert a given number (1 to 4999) to corresponding roman numeral. RRS feed

  • Question

  • include<stdio.h>
    #include<conio.h>

    void main()
    {
    int n,i,k;
    struct Roman
      {
    char *s;
    int v;
      };
    struct Roman R[]={{"M",  1000},{"CM",  900},{"D",   500},{"CD",  400},{"C",   100},{"XC",   90},{"L",    50},{"XL",   40},{"X",    10},{"IX",    9},{"V",     5},{"IV",    4},{"I",     1}};
    static char rstr[20];
    rstr[0] = '\0';


    clrscr();
    printf("Enter the number:->  ");
    scanf("%d",&n);
    k=n;
    for (i=0; n ; i++)
      {
    while ( RIdea.v <= n )
        {
    strcat( rstr, RIdea.s );
    n -= RIdea.v;
        }
      }
    printf("Roman equivalent of %d is %s",k,rstr);
    getch();
    }

     
    Monday, March 12, 2007 11:25 AM

All replies

  • Thanks a lot for this program, you did the solution very efficiently in lesser lines of code :)
    Monday, March 12, 2007 4:03 PM
  • Thats good dude.. did u solve it urself?
    Tuesday, March 13, 2007 8:57 AM
  • really nice efforts. good work jabed. Smile
    Tuesday, March 13, 2007 7:46 PM
  • good work really nice program
    Wednesday, March 14, 2007 6:27 AM