T:判断一个数是否为回文数
如:121
12321
1234321
#include<stdlib.h>
#include<stdio.h>
int main()
{
int len=0,i=0,j;
int num=123921;
int a[10]={0};
while(num)
{
a[i]=num%10;
num=num/10;
i++;
}
j=i;
while(j>=i/2)
{
if(a[j]!=a[i-j])
{
printf("Not!\n");
system("pause");
exit(0);
}
else
{
j--;
}
}
printf("Yes\n");
system("pause");
return 0;
}
2.判断一个字符串是否为回文字符串
如:“1234321”
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void judge(char *p,int len)
{
char* star,*end;
star=p;
end=p+len-1;
while(star<end)
{
if(*star!=*end)
{
printf("Not!\n");
system("pause");
exit(0);
}
else
{
star++;
end--;
}
}
printf("Yes!\n");
}
int main()
{
int LEN=0;
char arr[]="124321";
LEN=strlen(arr);
judge(arr,LEN);
system("pause");
return 0;
}
转载于:https://blog.51cto.com/10707460/1754035