题目:
回文数的形成。任取一个十进制整数,将其倒过来后与原来的整数相加,得到一个新的整数后,重复以上步骤,最终可得到一个回文数,请编程验证。
**输入格式要求:"%ld" 提示信息:"please enter a number optionaly:" "The generation process of palindrome:n" " input error, break.n"
**输出格式要求:" [%d]: %ld+%ld=%ldn" "Here we reached the aim at last !n"
程序运行示例如下:
please enter a number optionaly:345
The generation process of palindrome:
[1]: 345+543=888
Here we reached the aim at last !
代码如下:
#include#include long int reverse(long int n);//用来反转数字 int check(long int n);//用来判断是否是回文数 int main() { int count=0;//计算反转的次数,初始化为0 long int num,reve=0,sum=0,flag=0; printf("please enter a number optionaly:"); scanf("%ld",&num); if(num<0)//错误输入终端程序 { printf(" input error, break.n"); return 0; } do{ count++;//每循环一次,计数一次。 sum=0;//计算反转和未反转的数字的和 reve=reverse(num);//反转 sum=num+reve; printf(" [%d]: %ld+%ld=%ldn",count,reve,reverse(reve),sum);//输出 num=sum;//讲下轮要反转的数字赋值给num flag=check(sum); }while(flag);//当flag=0时,就跳出循环 printf("Here we reached the aim at last !n"); } long int reverse(long int n) { int temp=n,count=0,temp1,w,sum=0; do//计算输入函数的数字的位数 { temp/=10; count++; }while(temp>0); w=count;//临时存储一下位数 for(int i=0;i 运行结果如下:



