输出特殊形状的图形
輸出如下面這種形狀的圖形:
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;
}
總結
- 上一篇: 不使用库函数sqrt求平方根详解(牛顿迭
- 下一篇: 微软官方出的各种dll丢失的修复工具