例如:
abcdedcba就是回文数,从前完后读和从后往前读,到中间位置两个字符串完全相等。
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <math.h>
int Repeat(char *str)
{
int len = strlen(str);
int i;
int j;
int tmp;
for(i=0,j=len-1;i<=j;i++,j--)
{
if(str[i] == str[j])
{
tmp = 1;
}
else
{
tmp = 0;
break;
}
}
return tmp;
}
int main()
{
char *str = "abcdba";
if(Repeat(str))
{
printf("该字符串是回文数 \n");
}
else
{
printf("该字符串不是回文数 \n");
}
printf("%s\n",str);
return 0;
}