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

    Spørgsmål

  • 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();
    }

     
    12. marts 2007 11:25

Alle besvarelser