Skip to content

Instantly share code, notes, and snippets.

@rodorgas
Created March 2, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodorgas/f78eb5331f3f8bf25c065c64c1cc9399 to your computer and use it in GitHub Desktop.
Save rodorgas/f78eb5331f3f8bf25c065c64c1cc9399 to your computer and use it in GitHub Desktop.
Prova MAC
#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