long re(int a)
{
long int t;
for(t=0;a>0;a/=10)//将整数反序
t=t*10+a%10;
return t;
}
int nonre(lint n)//判断给定的整数是否为回文数
{
if(n>10 && n<2000)
{
if(re(n)==n)
return 1;//是返回1
else
return 0;//不是返回0
}
return 0;//不是返回0
}
void main()
{
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))//判断整数与其反序相加后是否为回文数
{
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");//输出最好得到的回文数
}
温馨提示:答案为网友推荐,仅供参考