为什么 C 中的递归不能按预期工作

发布于 01-20 06:53 字数 1432 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见终念2025-01-27 06:53:56

看看我的修改

void count_down_from(int num)
    {
        if (num >= 0) //need the >= operator to go down to zero not just 1
        {

            printf("%d\n", num);
            --num;
            count_down_from(num); //you need to send num to the call otherwise it won't be a recursive function
        }
        else
            return;
    }

take a look at my modifications

void count_down_from(int num)
    {
        if (num >= 0) //need the >= operator to go down to zero not just 1
        {

            printf("%d\n", num);
            --num;
            count_down_from(num); //you need to send num to the call otherwise it won't be a recursive function
        }
        else
            return;
    }
青萝楚歌2025-01-27 06:53:56

第二个块中的函数调用中缺少 (num)。

Missed (num) in function call in second block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文