C语言学习(13)

 1 //判断回文
 2 #include<stdio.h>
 3 #include<string.h>
 4 int main(){
 5     char s1[100];
 6     printf("请输入字符串\n");
 7     gets(s1);
 8     int n=0;
 9     for(;s1[n]!='\0';n++){
10 
11     }
12     n--;
13     int flag=1;//判断是否是回文的标志,1为是回文
14     for(int i=0;i<=n;i++,n--){
15         if(s1[i]!=s1[n]){
16             flag=0;
17             break;
18         }
19     }
20     if(flag==1){
21         printf("字符串s1是回文\n");
22     }else{
23         printf("字符串s1不是回文\n");
24     }
25     return 0;
26 }

猜你喜欢

转载自www.cnblogs.com/Tobi/p/9237534.html