zufeoj_习题5.6 打印杨辉三角形

题目链接:http://acm.ocrosoft.com/problem.php?cid=1172&pid=8

题目描述

输出以下的杨辉三角形(要求输出10行)

   1
   1   1
   1   2   1
   1   3   3   1
   1   4   6   4   1
   1   5  10  10   5   1

   ... ... ... ... ... ... ... ... ... ...

输入

输出

提示

每个整数占4位


#include<bits/stdc++.h>
using namespace std;
int a[11][11];
int main(){
    a[1][1]=1;
    for(int i=2;i<=10;i++){
        for(int j=1;j<=i;j++){
            a[i][j]=a[i-1][j-1]+a[i-1][j];
        }
    }
    for(int i=1;i<=10;i++){
        for(int j=1;j<=i;j++){
            printf("%4d",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/80747415