0
I need to create an algorithm that checks whether a number is palindromic or not. I decided to do this algorithm using a number as a string, but the program always returns that the numbers are not Palindromes.
char numero[10], numeroInvertido[10];
int i, j;
printf("Digite um numero : ");
scanf("%s",numero);
for (i = 0, j = 0; i < strlen(numero); i++, j++){
numeroInvertido[j] = numero[i];
}
if (numeroInvertido == numero)
printf("E um palindromo \n");
else
printf("Nao e um palindromo \n");
https://answall.com/q/448607/101
– Maniero
Comparing strings in C is not done through the operator
==
and yes with the functionstrcmp
of<string.h>
. In addition a string must always contain the terminator character ' 0'. In reality its comparison is checking whether the address ofnumeroInvertido
is equal to the address ofnumero
.– anonimo