C 语言程序判断回文

2025-05-11 15:09:19

1、ubuntu 14.04 linux cgcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

2、#include <stdio.h>#include <挢旗扦渌;stdlib.h>#include <string.h>#include <stdbool.h>bool is_plalindrome(char *str){ char *first=NULL,*last=NULL; int flag=0,str_len = 0; if(str == NULL) return false; else str_len = strlen(str); for(first=str,last=str+str_len-1;first <= last;first++,last--) { if(*first != *last){ flag = 0; break; } else flag = 1; } if(flag) return true; else return false;}int main(void){ char str[100]; gets(str); if(is_plalindrome(str)) printf("the str %s is plalindrome !!\n",str); else printf("the str %s is not plalindrome !!\n",str); return 0;}

3、xxx@linux:~/code$ gcc -o 坡纠课柩is_plalindrome is_plalindrome.cxx旌忭檀挢x@linux:~/code$ ./is_plalindrome123321the str 123321 is plalindrome !!xxx@linux:~/code$ ./is_plalindrome12the str 12 is not plalindrome !!

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢