输出如下面这种形状的图形:
4
3 7
2 6 9
1 5 8 10
C++ Code:
#include<iostream>
using namespace std;
//N: 代表有多少行元素
void Display(int N)
{
int i, j, v;
if(N <= 0)
{
cout<<"N must bigger than Zero(0)!"<<endl<<endl;
return;
}
for(i = 0; i < N; i++)
{
for(j = 0; j <= i; j++)
{
v = N * (j+1) - j * (j-1) / 2 - i;
cout<<v<<" ";
}
cout<<endl;
}
cout<<endl;
}
int main()
{
int X;
for(X = 0; X <= 15; X++)
Display(X);
return 0;
}