现在的位置: 首页 > 综合 > 正文

输出特殊形状的图形

2018年04月03日 ⁄ 综合 ⁄ 共 351字 ⁄ 字号 评论关闭

输出如下面这种形状的图形:

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;
}

抱歉!评论已关闭.