注册 登录
编程论坛 C++ Builder

C++编程求解

xzq0112 发布于 2016-10-28 20:43, 3970 次点击
c++,怎么编写一个递归函数,使其反序输出
2 回复
#2
yangfrancis2016-11-29 18:30
输出语句放在递归调用之后。
int recursive(int x)
{
     if(x<=0) cout<<"This is the innermost.";
     else
     {
          resursive(x-1);
          cout<<"这是从内向外第"<<x+1<<"层";
     }
}
//调用
recursive(5);
#3
袁广川2017-02-26 16:43
#include <iostream>
using namespace std;
void recurcive(int x)
{
    if(x<=0) cout<<"Please printf\n";
    else
    {
        recurcive(x-1);
        cout<<x<<" "<<'\n';
    }
 }
int main()
{
    int a;
    cin>>a;
    recurcive(a);
    return 1;
 }
1