怎么能够实现前几次输出都换行,输出最后一次的时候不换行?C++中,求解
-for循环 代码参考:
#include<iostream>
using namespace std;
int main()
{
int i, n;
cin >> n;
for(i = 0; i < n; i++)
{
if (i == n - 1 )
cout << i;
else
cout << i << endl;
}
cout << "nihao";
}
#include<iostream>
using namespace std;
int main()
{
int n = 10;
while (n > 0)
{
cout << n;
if (n - 1 > 0)
cout << endl;
n--;
}
cout << "nihao";
return 0;
}
具体看你代码了,实在不行,单独输出换行,肯定是容易实现的。