X-Git-Url: https://git.piment-noir.org/?p=Algorithmic_C.git;a=blobdiff_plain;f=TP4%2Fpalindrome.c;fp=TP4%2Fpalindrome.c;h=8ac573b3e91d40279927d88fecc2b5f9c7e3dd21;hp=a84c08f3c0ef0b50b0a6701d4ff0aaea627099a9;hb=c31b68a4e24e74a20f09aa1d7b9906b58d4aa255;hpb=915495850ca055b20497568512c3e70a6b61a13c diff --git a/TP4/palindrome.c b/TP4/palindrome.c index a84c08f..8ac573b 100644 --- a/TP4/palindrome.c +++ b/TP4/palindrome.c @@ -5,38 +5,48 @@ #define LEN_MAX 40 -bool palindrome_iter(char* mot, int longeur) { +bool palindrome_iter(char *mot, int longeur) +{ int i = 0; int j = longeur - 1; while (i <= j) { - if (mot[i] != mot[j]) { return false; } - i++; - j--; + if (mot[i] != mot[j]) { + return false; + } + i++; + j--; } return true; } -bool palindrome_rec_aux(char* mot, int i, int j) { - if (i >= j) { return true; } - if (mot[i] != mot[j]) { return false; } - return palindrome_rec_aux(mot, i+1, j-1); +bool palindrome_rec_aux(char *mot, int i, int j) +{ + if (i >= j) { + return true; + } + if (mot[i] != mot[j]) { + return false; + } + return palindrome_rec_aux(mot, i + 1, j - 1); } -bool palindrome_rec(char* mot, int longueur) { - return palindrome_rec_aux(mot, 0, longueur-1); +bool palindrome_rec(char *mot, int longueur) +{ + return palindrome_rec_aux(mot, 0, longueur - 1); } -int main() { +int main() +{ char mot[LEN_MAX]; printf("Saisir un mot\n"); scanf("%s", mot); if (palindrome_rec(mot, strlen(mot))) - printf("%s est un palindrome\n", mot); + printf("%s est un palindrome\n", mot); else - printf("%s n'est pas un palindrome\n", mot); + printf("%s n'est pas un palindrome\n", mot); return 0; }