cout<<' '<< f(x);在这里显示?

发布于 2025-02-03 07:48:27 字数 551 浏览 2 评论 0原文

#include <bits/stdc++.h>
using namespace std;
int f(int x)
{
    int n;
    if(x>0)
    {
        if(x%2==0)
        {
            cout<<x%10;
            n=1+f(x/10);
        }
        else
        {
            n=1+f(x/10);
            cout<<x%10;
        }
        return n;
    }
    else
        return 0;
}

int main()
{
    cout<<' '<<f(8174);
    return 0;
}

因此,在我的计算机上显示“ 48174”,但在我朋友的计算机上显示“ 4817 4”。本书中的正确答案是“ 4817 4”。我不明白为什么这个空间在数字之间,因为我称Cout&lt;'' ';在调用功能之前。您能帮我了解哪种方法是正确的?

#include <bits/stdc++.h>
using namespace std;
int f(int x)
{
    int n;
    if(x>0)
    {
        if(x%2==0)
        {
            cout<<x%10;
            n=1+f(x/10);
        }
        else
        {
            n=1+f(x/10);
            cout<<x%10;
        }
        return n;
    }
    else
        return 0;
}

int main()
{
    cout<<' '<<f(8174);
    return 0;
}

So on my computer it displays " 48174" but on my friend's computer it displays "4817 4". The correct answer in the book is "4817 4". I don't understand why would the space be between numbers because I call cout<<' '; before I call the function. Can you help me understand which is the right way?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文