/****************************************
* File Name : figure.c
* Creat Data : 2015.1.30
* Author : ZY
*****************************************/
/*定理与猜想*/
/*回文数的形成*/
/*任取一个十进制整数,将其倒过来后与原来的整数相加,
得到一个新的整数后重复以上步骤,则最终可得到一个回文数
,请编程验证*/
#include <stdio.h>
#define MAX 2147483647//限定M+N的范围
int long re(long a)//将整数反序
{
long t;
for(t = 0;a > 0;a /= 10)
{
t = t*10+a%10;
}
return t;
}
int nonre(long s)//判断是否是回文数
{
if(re(s) == s)
{
return 1;
}
else
{
return 0;
}
}
int main(void)
{
long n ,m;
int count = 0;
printf("please enter a number optionaly:");
scanf("%ld",&n);
printf("The generation process of palindrpme:\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]:%ld+%ld = %ld\n",++count,n,m,m+n);
//输出最后的回文数
printf("Here we reached the aim at last!\n");
return 0;
}
定理与猜想(回文数的形成)
最新推荐文章于 2022-06-13 13:18:47 发布