Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct{
- int value;
- char *roman;
- unsigned char usage;
- } romanDigit;
- int main()
- {
- romanDigit digits[13] ={
- {.value=1000,.roman="M",.usage=3},
- {.value=900,.roman="CM",.usage=3},
- {.value=500,.roman="D",.usage=3},
- {.value=400,.roman="CD",.usage=3},
- {.value=100,.roman="C",.usage=3},
- {.value=90,.roman="XC",.usage=3},
- {.value=50,.roman="L",.usage=3},
- {.value=40,.roman="XL",.usage=3},
- {.value=10,.roman="X",.usage=3},
- {.value=9,.roman="IX",.usage=3},
- {.value=5,.roman="V",.usage=3},
- {.value=4,.roman="IV",.usage=3},
- {.value=1,.roman="I",.usage=3}
- };
- int bekert = 0;
- char output[35] = {0};
- while(1){
- printf("Irjon be egy szamot 1 es 4999 kozt!\n");
- scanf("%d",&bekert);
- if(bekert<1||bekert>4999){
- printf("Szamtartomanyon kivuli ertek.\n");
- }
- else break;
- }
- for(int i=0;bekert>0;){
- //printf("Teszt %d-re \n",digits[i].value);
- if(bekert-digits[i].value >= 0){
- bekert -= digits[i].value;
- strcat(output,digits[i].roman);
- }
- else{
- i++;
- }
- }
- printf("A szam romai alakja: %s\n",output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement