在同一个程序中从函数y中调用函数x,反之亦然

Calling function x from within function y and vice versa in the same program

本文关键字:函数 反之亦然 调用 同一个 程序      更新时间:2023-10-16
int right(int n)
{
        if(n>0)
        {
            n--;
            top_lim ++;
            cout<<"R";
            right_lim--;
            if(right_lim < size)
            return(right(n-1));
            if(top_lim>0)
-->            return(up(n - 1));
        }
        else
        {
            return 0;
        }
}
int up(int n)
{
if(n>1)
        {
            n--;
            top_lim --;
            cout<<"U";
            if(right_lim < size)
            return(right(n-1));
            if(top_lim > 0 )
            return(up(n-1));
        }
        else
        {
            return 0;
        }
}
error: [17] 'up' was not declared in this scope|--> indicates error in code ..

问题描述:

问题是找出n*n网格中从(0,0)到(n,n)的对角线以下部分的所有可能路径数我基本上首先在main函数中调用正确的函数,然后它应该打印出所有的路径。

是否有解决这个问题的方法?

在代码顶部添加一个向前声明:

int up(int);

(确保用完全优化编译代码!): -)