1.判断一个数是不是回文数,如:"123321"
#include <stdio.h>
int main()
{
int m=1234; //m是要判断的数
int n=0; //n是反转后的数
int ret=m;
while(m)
{
n=n*10+m%10;
m/=10;
}
if(ret==n)
{
printf( "Yes!\n");
}
else
{
printf( "No!\n");
}
system( "pause");
return 0;
}
2.判断一个字符串是不是回文字符串,如:"abc1234321cba"
#include <stdio.h>
int main()
{
char *str= "12355321";
char *start=str;
char *end=str+strlen(str)-1;
while(start<end)
{
if(*start==*end)
{
start++;
end--;
}
else
{
printf( "No!\n");
system( "pause");
return 0;
}
}
printf("Yes!\n");
system("pause");
return 0;
}
本文出自 “追寻内心的声音” 博客,转载请与作者联系!