#include
int main(int argc, char const *argv[])
{
int n = 0, n1 = 0;
int i = 0, j = 0;
char buf[6] = {0};
while(1)
{
scanf("%d",&n);
if(n <= 0 || n >= 100000)
printf("Error is n,pls try again.\n");
else
break;
}
n1 = n;
while(n1)
{
buf[i] = n1 % 10;
n1 /= 10 ;
i++;
}
while(i--)
{
n1 *= 10;
n1 += buf[j];
j ++;
}
printf("n: %d n1: %d\n", n, n1);
if(n == n1)
printf("YES\n");
else
printf("NO\n");
return 0;
}
把数字当作字符串读入,然后用这个函数就行了。
int ishw(char *p)
{
if(*p == '\0')
return 1;
char *q=p;
while(*q!='\0')
q++;
if(*p!=*--q)
return 0;
else
{
*q='\0';
return ishw(p+1);
}
}