il faut déterminer si une suite d'entiers saisis par l'utilisateur est un palindrome, c'est-à-dire qu'elle peut se lire à
l'identique de gauche à droite ou de droite à gauche (ex : 3 2 4 2 3).
quelqun a une idée pour un programme en C. j'vais penser a
int main(void)
{ bool Palindrome(int monTableau[], int min, int max)
Ajoute la ligne getch(); à la fin de ton programme et il sera interrompu jusqu'à ce que tu appuies sur Enter.
Ainsi tu aura le temps de lire le résultat.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
int IsPalindrome(char s[])
{
int i, length;
length = strlen(s);
for (i=0; i<length/2; i++) {
if (s[i] != s[length-1-i])
return FALSE;
}
return TRUE;
}
int main() {
char chaine[64];
printf("entrez une chaine\n");
gets(chaine);
if (IsPalindrome(chaine)) {
printf("%s est un palindrome\n", chaine);
} else {
printf("%s n_est pas un palindrome\n", chaine);
}
system("pause");
return 0;
}
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
int IsPalindrome(char s[])
{
int i, length;
length = strlen(s);
for (i=0; i<length/2; i++) {
if (s[i] != s[length-1-i])
return FALSE;
}
return TRUE;
}
int main() {
char chaine[64] = "bob";
if (IsPalindrome(chaine)) {
printf("’%s’ est un palindrome\n", chaine);
} else {
printf("’%s’ n’est pas un palindrome\n", chaine);
}
return 0;
}
quelqun peut me dire si cette fonction marche , merci
lami20j
Messages postés21331Date d'inscriptionjeudi 4 novembre 2004StatutModérateur, Contributeur sécuritéDernière intervention30 octobre 20193 567 17 mars 2008 à 20:30
Salut,
voici un autre
#include <stdio.h>
#include<string.h>
int main (int argc, char **argv)
{
char mot[20];
int i, j, palindrome;
palindrome = 0;
printf ("Entrez un mot : ");
scanf ("%s", mot);
getchar();
for (i = 0, j = strlen (mot) - 1; i <= j; ++i, --j){
if (mot[i] == mot[j])
palindrome = 1;
else {
palindrome = 0;
break;
}
}
if (palindrome)
printf ("%s est un palindrome\n", mot);
else
printf ("%s est n'est pas un palindrome\n", mot);
getchar();
return 0;
}
si tu veux que ce s'affiche t'a qu'a ajouter la bibliothèque #include<stdlib.h> et ajouter system("pause"); oubien tu peux ajouter un scanf("%"); meme si c déconseillé mais fait juste le temps de voir si ca marche :D
17 mars 2008 à 20:26
implicit declaration of function `int getch(...)'
t'a une idée ?
13 déc. 2010 à 15:02
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
int IsPalindrome(char s[])
{
int i, length;
length = strlen(s);
for (i=0; i<length/2; i++) {
if (s[i] != s[length-1-i])
return FALSE;
}
return TRUE;
}
int main() {
char chaine[64];
printf("entrez une chaine\n");
gets(chaine);
if (IsPalindrome(chaine)) {
printf("%s est un palindrome\n", chaine);
} else {
printf("%s n_est pas un palindrome\n", chaine);
}
system("pause");
return 0;
}