#include
#define MAX 2147483648 //限制M+N的范围
long re(long int a)//求输入整数的反序
{
long int t;
for(t=0;a>0;a/=10)//将整数反序
t=t*10+a%10;
return t;
}
int nonre(long int s)//判断给定的整数是否为回文数
{
if(re(s)==s)
return 1;//是返回1
else
return 0;//不是返回0
}
void main()
{
long int n,m;
int count=0;
printf("please input a number optionaly:");
scanf("%ld",&n);
printf("The genetation process of palindrome:\n");
while(!nonre((m=re(n))+n))//判断整数与其反序相加后是否为回文数
{
if((m+n)>=MAX)//超过界限输出提示信息
{
printf("input error,break.\n");
break;
}
else
{
printf("[%d]:%ld+%ld=%ld\n",++count,n,m,m+n);
n+=m;//累加
}
}
printf("[%d]:%d+%ld=%ld\n",++count,n,m+n);
printf("Here we reached the aim at last.\n");//输出最好得到的回文数
}