【发布时间】:2022-01-03 02:09:50
【问题描述】:
问题
如何在数字之间给出空格?当我在cout<<j 之后添加<<" " 时,模式发生了变化。有没有其他方法可以在数字之间留出空格?
代码
#include<iostream>
using namespace std;
int main(){
int i,j=1,space,star,n;
cin>>n;
i=1;
循环
while(i<=n){
space=n-i;
while(space){
cout<<" ";
space--;
}
star=i;
while(star){
cout<<j<<" ";
j++;
star--;
}
cout<<"\n";
i++;
}
return 0;
}
输出 对于 n=4
1
23
456
78910
我想要这个输出:-
1
2 3
3 4 5
7 8 9 10
【问题讨论】: