cout<<' '<< f(x);在这里显示?
#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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论