程序要求:
回文判断,例如字符串为“12321”,则符合回文条件,即倒置后与原字符串相同。故返回1,否则返回0.
程序代码:
- #include <stdio.h>
- #include <string.h>
- int huiwen(const char *);
- int main()
- {
- int n;
- char buf[20] = "12521";
- n = huiwen(buf);
- printf("the res =%d\n",n);
- return 0;
- }
- int huiwen(const char *p)
- {
- char *begin;
- char *end;
- int len = 0;
- len = strlen(p);
- begin = p;
- end = p + len -1;
- while(*begin != '\0')
- {
- if(*begin == *end)
- {
- begin ++;
- end --;
- }
-
- }
- if(*begin == '\0')
- return 1;
- else
- return 0;
- }
阅读(1972) | 评论(0) | 转发(0) |