2018年购置税还减半吗:用C语言编程:判断一个字符串是否正与倒读都是同一字符串.

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/25 03:24:42
判断一个字符串是否正与倒读都是同一字符串.

#include"stdio.h"
#include"string.h"
int test(char *p2,int nx)
{ int i,ispalx=1;
for(i=0;i<nx/2;i++)
if(*(p2+i)!=*(p2+nx-i-1))
{ ispalx=0;
break;
}
return(ispalx);
}
void jieshou(char *p2)
{ printf("Enter string to test:\n");
gets(p2);
}
void shuchu(int ispalx)
{ if(ispalx)
printf("A palindrome");
else
printf("Not a palindrome");
}
void main()
{ int i,n,ispal;
char str[100],*p;
p=str;
jieshou(p);
n=strlen(str);
ispal=test(p,n);
shuchu(ispal);
}