TP5 exo4: implement more functions
[Algorithmic_C.git] / TP4 / palindrome.c
index a84c08f3c0ef0b50b0a6701d4ff0aaea627099a9..8ac573b3e91d40279927d88fecc2b5f9c7e3dd21 100644 (file)
@@ -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;
 }