Created
March 2, 2018 11:19
-
-
Save rodorgas/f78eb5331f3f8bf25c065c64c1cc9399 to your computer and use it in GitHub Desktop.
Prova MAC
This file contains 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> | |
const char grupos[10][5] = {"", "", "abc", "def", "ghi", "jkl", | |
"mno", "pqrs", "tuv", "wxyz"}; | |
void gerarPalavra(int number[], int curr_digit, char output[], int n) | |
{ | |
int i; | |
if (curr_digit == n) | |
{ | |
printf("%s ", output); | |
return ; | |
} | |
for (i=0; i<strlen(grupos[number[curr_digit]]); i++) | |
{ | |
output[curr_digit] = grupos[number[curr_digit]][i]; | |
gerarPalavra(number, curr_digit+1, output, n); | |
if (number[curr_digit] == 0 || number[curr_digit] == 1) | |
return; | |
} | |
} | |
void imprimir(int number[], int n) | |
{ | |
char result[n+1]; | |
result[n] ='\0'; | |
gerarPalavra(number, 0, result, n); | |
} | |
int main(void) | |
{ | |
int number[] = {2, 3, 4}; | |
int n = sizeof(number)/sizeof(number[0]); | |
imprimir(number, n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment