输入正数n(n<=10),输出下列形状的三角形。例如:当n=5时输出:
11
7 12
4 8 13
2 5 9 14
1 3 6 10 15
输入格式
一行,一个整数
输出格式
n行,每个有若干个整数,每个整数占4列
输入/输出例子1
输入:
5
输出:
11
7 12
4 8 13
2 5 9 14
1 3 6 10 15
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,a[100][100]={0};
cin>>n;
int s=1;
int k=n;
i=n-1;
j=0;
int s1=0,s2;
while(k)
{
k--;
while(i<=n-1)
{
a[i][j]=s;
s1=i;
i++,j++;
s++;
}
i=k;
i--;j=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!=0)
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}