新数字三角形
描述
读入一个正整数n,输出一个n行的数字三角形(见输出样例)。
输入
一行一个正整数n,2≤n<100。
输出
共n行,第i行包含i个正整数,每个整数占5列。
输入样例 输出样例
5 1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
c++代码:
#include<iostream>
using namespace std;
int main()
{
int n,a;
cin>>n;
a=n;
for(int i=0;i<=a;i<=a;i++)
{
for(int j=0;j<i;j++) cout<<" ";
for(int k=1;k<=n;k++) cout<<setw(5)<<k;
n--;
cout<<n;
}
return 0;
}