#include
using namespace std;
void getReverseChar(char* str)
{
if (*str == '\0') {
return;
}else
{
getReverseChar(str+1);
cout<<*str;
}
}
int main(int argc, const char * argv[]) {
char array[20];
cout<<"请输入要逆序的字符串";
cin>>array;
getReverseChar(array);
cout<<"\n";
return 0;
}
结果:
请输入要逆序的字符串helloworld
dlrowolleh
Program ended with exit code: 0
逆序输出字符串采用递归的方式
最新推荐文章于 2022-04-27 23:33:59 发布