判断字符串是否回文(c语言指针)

20291.

判断字符是否是回文

“回文”是一种顺序读和反序读都一样的字符串,例如:“121”“abcba” “ABCCBA”编写程序,判断任一字符串是否为回文。

【输入用例2】12321

【输出用例2】yes

【输入用例3】1234

【输出用例3】no

#include 
#include 
void judge(int len,char *p)
{
    int i,j;
    for(i = 0,j = len - 1;i <= len;i++,j--)
    {
        if(*(p+i) != *(p+j))
        {
            printf("no");
            break;
        }
    }
    if(i >= j)
    {
        printf("yes");
    }
}
int main()
{
    char a[20];
    gets(a);
    char *p;
    p = &a;
    int length;
    length = strlen(a);
    judge(length,a);
    return 0;
}

你可能感兴趣的:(c语言,开发语言,后端)