#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *strrev(char *str)
{
char *p1, *p2;
if (! str || ! *str)
return str;
for (p1
= str
, p2
= str
+ strlen(str
) - 1; p2
> p1
; ++p1
, --p2
) {
char temp = *p1;
*p1 = *p2;
*p2 = temp;
}
return str;
}
int main(void) {
int numberWantToCheck;
printf("What's the number you want to check?\n"); scanf("%d", &numberWantToCheck
); int bufferSize
= snprintf(NULL
, 0, "%d", numberWantToCheck
) + 1;
char stringOfTheNum[bufferSize];
char reversedNum[bufferSize];
snprintf(stringOfTheNum
, bufferSize
, "%d", numberWantToCheck
); // converte numero para String strcpy(reversedNum
, stringOfTheNum
); // copia a string para reversedNum strrev(reversedNum); // inverte reversedNum
if(strcmp(reversedNum
, stringOfTheNum
) == 0) { printf("The number is palindrome.\n"); } else {
printf("The number is not palindrome.\n"); }
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHN0cmluZy5oPgoKY2hhciAqc3RycmV2KGNoYXIgKnN0cikKewogICAgY2hhciAqcDEsICpwMjsKCiAgICBpZiAoISBzdHIgfHwgISAqc3RyKQogICAgICAgIHJldHVybiBzdHI7CiAgICBmb3IgKHAxID0gc3RyLCBwMiA9IHN0ciArIHN0cmxlbihzdHIpIC0gMTsgcDIgPiBwMTsgKytwMSwgLS1wMikKICAgIHsKICAgICAgICBjaGFyIHRlbXAgPSAqcDE7CiAgICAgICAgKnAxID0gKnAyOwogICAgICAgICpwMiA9IHRlbXA7CiAgICB9CiAgICByZXR1cm4gc3RyOwp9CgppbnQgbWFpbih2b2lkKSB7CiAgICBpbnQgbnVtYmVyV2FudFRvQ2hlY2s7CiAgICBwcmludGYoIldoYXQncyB0aGUgbnVtYmVyIHlvdSB3YW50IHRvIGNoZWNrP1xuIik7CiAgICBzY2FuZigiJWQiLCAmbnVtYmVyV2FudFRvQ2hlY2spOwoJaW50IGJ1ZmZlclNpemUgPSBzbnByaW50ZihOVUxMLCA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