36 lines
778 B
C
36 lines
778 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int f(const char s[]) {
|
|
uint len = strlen(s);
|
|
uint i = 0;
|
|
while (i < len / 2) {
|
|
if (s[i] != s[len - 1 - i]) {
|
|
return 0;
|
|
}
|
|
i++;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int main() {
|
|
char s1[] = "baab";
|
|
char s2[] = "kayak";
|
|
char s3[] = "Hello Word!";
|
|
if (f(s1)) {
|
|
printf("\"%s\" est un palindrome\n", s1);
|
|
} else {
|
|
printf("\"%s\" n'est pas un palindrome\n", s1);
|
|
}
|
|
if (f(s2)) {
|
|
printf("\"%s\" est un palindrome\n", s2);
|
|
} else {
|
|
printf("\"%s\" n'est pas un palindrome\n", s2);
|
|
}
|
|
if (f(s3)) {
|
|
printf("\"%s\" est un palindrome\n", s3);
|
|
} else {
|
|
printf("\"%s\" n'est pas un palindrome\n", s3);
|
|
}
|
|
} |