题目链接:http://codeup.cn/problem.php?cid=100000569&pid=2
#include<bits/stdc++.h>
using namespace std;int main()
{
const int LEN = 10;int triangle[LEN][LEN]={
0};int n;scanf("%d", &n);int i, j;if(n <= LEN) {
for(i=0; i<LEN; i++) {
triangle[i][0] = 1;triangle[i][i] = 1;}for(i=2; i<n; i++) {
for(j=1; j<i; j++) {
//非第0列和非对称轴上的数,其值等于正上方和左上两数相加的和triangle[i][j] = triangle[i-1][j] + triangle[i-1][j-1];}}for(i=0; i<n; i++) {
for(j=0; j<i; j++) {
printf("%d ", triangle[i][j]);}printf("%d\n", triangle[i][j]);}}return 0;
}
运算结果