Created
May 27, 2009 11:25
-
-
Save elomar/118592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<string.h> | |
| int subpadrao(char romano[], int decimal, int base, char letra_1, char letra_5, char letra_10) { | |
| while(decimal >= 10 * base) { | |
| strncat(romano, &letra_10, 1); | |
| decimal -= 10 * base; | |
| } | |
| if(decimal >= 9 * base) { | |
| strncat(romano, &letra_1, 1); | |
| strncat(romano, &letra_10, 1); | |
| decimal -= 9 * base; | |
| } | |
| if(decimal >= 5 * base) { | |
| strncat(romano, &letra_5, 1); | |
| decimal -= 5 * base; | |
| } | |
| if(decimal >= 4 * base) { | |
| strncat(romano, &letra_1, 1); | |
| strncat(romano, &letra_5, 1); | |
| decimal -= 4 * base; | |
| } | |
| while(decimal >= 1 * base) { | |
| strncat(romano, &letra_1, 1); | |
| decimal -= 1 * base; | |
| } | |
| return decimal; | |
| } | |
| main() { | |
| int decimal, restante = 0; | |
| char romano[20] = {'\0'}; | |
| do { | |
| printf("digite um número:"); | |
| scanf("%i", &decimal); | |
| restante = subpadrao(romano, decimal, 100000, 'c', 'd', 'm'); | |
| restante = subpadrao(romano, restante, 10000, 'x', 'l', 'm'); | |
| restante = subpadrao(romano, restante, 1000, 'M', 'v', 'x'); | |
| restante = subpadrao(romano, restante, 100, 'C', 'D', 'M'); | |
| restante = subpadrao(romano, restante, 10, 'X', 'L', 'C'); | |
| restante = subpadrao(romano, restante, 1, 'I', 'V', 'X'); | |
| printf("em romano: %s\n", romano); | |
| //romano[0] = '\0'; | |
| strcpy(romano, ""); | |
| } while (decimal > 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment