1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <stdio.h>
void appliquerPermutation(char* resultat, const char* mot, const int* tabPermutation, int taillePermutation)
{
// une petite boucle effacée dans laquelle j'avais
// rempli les autres caractères du résultat
resultat[taillePermutation] = '\0'; // Les chaînes du langage C doivent se terminer par '\0'.
}
int main()
{
const char mot1[5] = "ABAC";
const int permutation1[4] = {3, 2, 0, 1};
char mot1_apres_permutation[5];
appliquerPermutation(mot1_apres_permutation, mot1, permutation1, 4);
printf("Le 1er mot apres permutation vaut : %s.\n", mot1_apres_permutation);
const char mot2[5] = "ABCD";
const int permutation2[4] = {2, 1, 3, 0};
char mot2_apres_permutation[5];
appliquerPermutation(mot2_apres_permutation, mot2, permutation2, 4);
printf("Le 2e mot apres permutation vaut : %s.\n", mot2_apres_permutation);
return 0;
} |
Partager