怎么判断一个数是不是回文数?

sms88 2005-03-26 08:29:00
所谓回文数是指其各位数字左右对称的整数,例如121,676,94249等
...全文
1534 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
heguosheng 2005-04-18
  • 打赏
  • 举报
回复
收藏
llf_hust 2005-03-27
  • 打赏
  • 举报
回复
int Test(int n)
{
int i, j;
j = 0;
i = n;
while (i)
{
j = j*10 + i%10;
i /= 10;
}
return n == j;
}
ChenFengqing 2005-03-27
  • 打赏
  • 举报
回复
同意无效,呵呵!
SolidRabbit 2005-03-27
  • 打赏
  • 举报
回复
"相信我,不是注释越多越好。。"

同意,注释只是用来说明一些不易懂的地方的 ,如果注释太多的话会影响程序的清晰性
清晰总是伴着简洁而来的

wind5110 2005-03-26
  • 打赏
  • 举报
回复
相信我,不是注释越多越好。。
wind5110 2005-03-26
  • 打赏
  • 举报
回复
#include <stdio.h>
main(){
char *s;
int front,rear;
front=0;
gets(s);
rear=strlen(s)-1;
while(front<rear){
if(s[front]!=s[rear])break;
front++;
rear--;
}
if(front>=rear)puts("YES\n");
else puts("NO\n");
system("pause");
}
stupidfish2004 2005-03-26
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/TopicView3.asp?id=3862458
rocklabzhang 2005-03-26
  • 打赏
  • 举报
回复
int hw(int n)
{
int m=0,v=n;
while(v>0)
{
m=m*10+v%10; 翻转
v/=10; //取出当前位
}
return (m==n);
}
pcboyxhy 2005-03-26
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
char str[100], *start=str, *end=str;
char tab[][20]={"It is.\n\n","It's Not.\n\n"};
gets(str);
while(*end++); //将end指针移到字符串末尾,最后一次当指向 '\0'时还自增一次
end-=2; // 所以减去2来调整。
while((*start==*end) && (start<=end)) //比较
{
++start;
--end;
} //start<end说明没有匹配完就跳出了,
//就是说两边不对称
printf("%s", tab[start<end]);
system("PAUSE");
return 0;
}

再让你讨厌一下
sms88 2005-03-26
  • 打赏
  • 举报
回复
最讨厌没有注释的程序了!
cfadongdongcfa 2005-03-26
  • 打赏
  • 举报
回复
int main(void)
{
long num = 123454321;
char temp[512];
char len = 0;
int i;
memset(temp, 0, 512);
sprintf(temp, "%d", num);
len = strlen(temp);
for (i=0; i<len/2; i++){
if (temp[i]!=temp[len-i-1]) break;
}
return (i==len/2) ;
}
CMyMfc 2005-03-26
  • 打赏
  • 举报
回复
先转成字符串
折半循换比较, 比较前后对应字符是否相等,如不相等break;
如果遍历完, 则是回文

70,038

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧