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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <stdio.h>
#include<string.h>
#include<stdbool.h>
int main (int argc, char **argv)
{
//declaration de variable
char mot [100];
//saisie du texte
scanf("%100[^\n]%*c", mot);
// conversion des majuscule en minuscule
{ int i, j=-1;
for(i=0;mot[i]!='\0';i++)
{
if(mot[i]>='A' && mot[i]<='Z')
mot[i]=(mot[i]-'A')+'a';
}
}
//Supression des espaces
{
int i, j=-1;
for (i = 0; mot[i]; i++)
if (mot[i] != ' ')
mot[++j] = mot[i];
mot[++j] = '\0';
}
//comparaison
{
int i, j=-1;
bool palindrome=true;
for (i = 0, j = strlen (mot) - 1; i <= j; ++i, --j)
{
if (mot[i] != mot[j])
palindrome = false;
}
//resolution
{
if (palindrome == true)
printf ("%s est un palindrome\n", mot);
else
printf ("%s n'est pas un palindrome\n", mot);
}
}
return 0;
} |