类似神道丹尊的小说:判断回文的程序

来源:百度文库 编辑:高考问答 时间:2024/05/04 13:11:55
回文是指正向读和反向读都一样的一段数字或者文字,如321123或“able was I ere I saw elba”。编写程序,输入一个9位整数,并判断它是否是回文。
1.如果输入数不是9位整数,则显示一个错误信息如“1234 is not a n-digit number”;(其中1234是输入的数值,n为four、five、six、seven、eight、nine等)
2.输出格式如“12221 is a palindrome!”,“12223 is not a palindrome!"
请大家帮我写一个能满足以上要求的c程序。

#include <stdio.h>

main()
{
int i,j,a,b,s=0,n=0,s0;
b=0;
scanf("%d",&s);
s0 = s;
do
{
s=s/10;
n++;
}
while (s>0);
s = s0;
for (i=1;i<=n;i++)
{
a=s%10;
s=s/10;
b=b+a;
}
printf("%d\n",b);
}