C 语言程序判断回文

作者:落知秋 | 创建时间: 2023-07-22
回文:把相同的词汇或句子,在下文中调换位置或颠倒过来,产生首尾回环的情趣,叫做回文。...
C 语言程序判断回文

操作方法

ubuntu 14.04 linux c gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.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; }

xxx@linux:~/code$ gcc -o is_plalindrome is_plalindrome.c xxx@linux:~/code$ ./is_plalindrome 123321 the str 123321 is plalindrome !! xxx@linux:~/code$ ./is_plalindrome 12 the str 12 is not plalindrome !!

点击展开全文

更多推荐