#include <stdio.h>
#include <stdlib.h>
//1、用递归判断传入的字符数组中的元素是否对称,如果对称,返回1,否则返回0。
int getCmp(char str[],int start,int end);
int main(){
char str[50];
int start=0;
printf(“请输入字符串!\n”);
gets(str);
int len=strlen(str);
printf("%d\n",len);
int end=len-1;
int result=getCmp(str,start,end);
if(len==1){
result=0;
}
printf("%d\n",result);
return 0;
}
int getCmp(char str[],int start,int end){
if(str[start++]==str[end–]){
if(start<end){
getCmp(str,start,end);
}else{
return 1;
}
}else{
return 0;
}
}
用递归判断一个字符串是否对称
最新推荐文章于 2022-10-05 16:41:34 发布