打印

作者: 极速魔法 | 来源:发表于2017-07-04 09:02 被阅读6次

1
3 2
4 5 6
10 9 8 7
。。。

#include<iostream>
#include<vector>

using namespace std;
void tri(int n){
    //init vector
  //line
    for(int i=1;i<=n;i++){
        //odd line begin 1,2,3...
        if(i%2){
            int aux=(i-1)*i/2+1;
//every line numbers count
            for(int j=1;j<=i;j++){
                cout<<aux<<" ";
                aux++;
            }
            cout<<endl;
        } else{
            int aux=i*(i+1)/2;
            for(int j=1;j<=i;j++){
                cout<<aux<<" ";
                aux--;
            }
            cout<<endl;
        }
    }

    

}

int main(){
    tri(5);
    return 0;
}

相关文章

网友评论

      本文标题:打印

      本文链接:https://www.haomeiwen.com/subject/kfethxtx.html