Advertisement
sskss73

Untitled

May 1st, 2021
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.     int value;
  6.     char *roman;
  7.     unsigned char usage;
  8. } romanDigit;
  9. int main()
  10. {
  11.     romanDigit digits[13] ={
  12.     {.value=1000,.roman="M",.usage=3},
  13.     {.value=900,.roman="CM",.usage=3},
  14.     {.value=500,.roman="D",.usage=3},
  15.     {.value=400,.roman="CD",.usage=3},
  16.     {.value=100,.roman="C",.usage=3},
  17.     {.value=90,.roman="XC",.usage=3},
  18.     {.value=50,.roman="L",.usage=3},
  19.     {.value=40,.roman="XL",.usage=3},
  20.     {.value=10,.roman="X",.usage=3},
  21.     {.value=9,.roman="IX",.usage=3},
  22.     {.value=5,.roman="V",.usage=3},
  23.     {.value=4,.roman="IV",.usage=3},
  24.     {.value=1,.roman="I",.usage=3}
  25.     };
  26.     int bekert = 0;
  27.     char output[35] = {0};
  28.     while(1){
  29.         printf("Irjon be egy szamot 1 es 4999 kozt!\n");
  30.  
  31.         scanf("%d",&bekert);
  32.         if(bekert<1||bekert>4999){
  33.             printf("Szamtartomanyon kivuli ertek.\n");
  34.         }
  35.         else break;
  36.     }
  37.     for(int i=0;bekert>0;){
  38.         //printf("Teszt %d-re \n",digits[i].value);
  39.         if(bekert-digits[i].value >= 0){
  40.             bekert -= digits[i].value;
  41.             strcat(output,digits[i].roman);
  42.         }
  43.         else{
  44.             i++;
  45.         }
  46.     }
  47.     printf("A szam romai alakja: %s\n",output);
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement