#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;
}