BackGround:
写一个递归算法来实现字符串逆序存储,要求:不另设串存储空间
#include<cstdio>
#include<windows.h>
#include<cmath>
void Reverse(char*str, int n)
{
int len;
char temp;
if (n<ceil(strlen(str) / 2.0)) return;
len = strlen(str) - n-1;
temp = str[n];
str[n] = str[len];
str[len] = temp;
Reverse(str, n - 1);
}
int main()
{
system("color 0A");
char StrArry[100] = {'\0'};
printf("请输入一串字符:\r\n");
scanf_s("%s", &StrArry,100);
printf("输入的字符串为:%s\r\n", StrArry);
Reverse(StrArry, ceil(strlen(StrArry) )- 1);
printf("反序输出为:%s", StrArry);
return 0;
}