關於楊輝三角

2021-09-11 08:15:28 字數 807 閱讀 2858

說好的寒假計畫…

不談了,以後就是不能相信在家裡能夠學習…

題目描述

11 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

上面的圖形熟悉嗎?它就是我們中學時候學過的楊輝三角。

輸入輸入包含多組測試資料,每組測試資料的輸入只有乙個正整數n(1 < = n < = 30),表示將要輸出的楊輝三角的層數,輸入以0結束。

輸出對於每乙個輸入,請輸出相應層數的楊輝三角,每一層的整數之間用乙個空格隔開,每乙個楊輝三角後面都加乙個空行。

樣例輸入23

0樣例輸出

11 1

11 1

1 2 1

**:

#include #include #include #include #include #include #include #define max1 30

using namespace std;

long long int a[max1][max1];//看例子應想到根據上一行上一列的關係來進行相加,關於行與列應想到使用二維陣列來定義每一行的數值;

int sanjiao(int k,int h)

else

//return a[i][j];}}

return a[k][h];

}}int main()

; for(int k = 1;k <= n;k++)

cout << endl;

}cout << endl;

}}

關於「楊輝三角」

楊輝三角,顧名思義,就是楊輝發現的三角 又稱賈憲三角形 帕斯卡三角形 1 1 11 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1.首先是等腰三角形 2.除了頂端和兩側是1之外,其餘數字全是它左上方的元素與其右上方的元素的和 3.第n行一定只有n個元素 4.每一行都是對稱...

python楊輝三角 楊輝三角I II

給定乙個非負整數 numrows,生成楊輝三角的前 numrows 行。在楊輝三角中,每個數是它左上方和右上方的數的和。示例 輸入 5 輸出 1 1,1 1,2,1 1,3,3,1 1,4,6,4,1 可以一行一行錯位加,當然這裡提供更簡便的方法。任取一行描述 1,2,1 如何得到 1,3,3,1 ...

Java 楊輝三角

public class yanghui 生成指定行數的楊輝三角形 param lines 楊輝三角形的行數 public void printyanghui int lines if lines 30 int line new int lines int maxlen getmaxlen line...