回文

编程判断输入的一个字符串是否是“回文”。所谓“回文”字符串就是从左读和从右读都一
样的字符串。例如: "abcba"就是一个回文字符串。
要求:先输出("Input a string:\n"),输入字符串,然后判断是否回文,最后输出
("This string is a plalindrome.\n")或者("This string is not a plalindrome.\n")

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 int fun(char a[])
 6 {
 7     int i,j;
 8     for (i=0,j=strlen(a); i<j; i++, j--)
 9     {
10         if (a[i]!=a[j])
11         {
12             return 0;
13         }
14     }
15     return 1;
16 }
17 
18 int main()
19 {
20     char a[80];
21     printf("Input a string:\n");
22     gets(a);
23     if(fun(a))
24         printf("This string is a plalindrome.\n");
25     else
26         printf("This string is not a plalindrome.\n");
27     return 0;
28 }

 

posted on 2014-05-14 16:03  crane_practice  阅读(271)  评论(0编辑  收藏  举报

导航