#include<stdio.h>
#include<math.h>
#define Yes 1
#define No 0
typedef short Status;
long Reverse(long x);
long Cal(long m);
Status Judge(long k);
int main()
{
long x;
printf("Please input the value of x : ");
scanf("%ld", &x);
if(Judge(x) == Yes)
{
printf("%ld是回文数.\n", x);
}
else
{
printf("%ld不是回文数.\n", x);
}
return 0;
}
/* 判断给定整数是否为回文数 */
Status Judge(long k)
{
if(k < 0)
{
return No;
}
else if(k == Reverse(k))
{
return Yes;
}
else
{
return No;
}
}
/* */
long Cal(long m)
{
long s = 1;
short i = 0;
while(i < m)
{
s *= 10;
i ++;
}
return s;
}
/* */
long Reverse(long x)
{
short p;/* 记录整数x的位数 */
long temp = x;
short i;
long r;
for(p = 0; temp > 0; p ++)
{
temp /= 10;
}/* √ */
for(i = 0, r = 0, temp = x; i < p; i ++, temp /= 10)
{
r = r + temp % 10 * Cal(p - i - 1);
}
return r;
}