E 楊輝三角

2021-08-01 10:09:14 字數 733 閱讀 9728

還記得中學時候學過的楊輝三角嗎?具體的定義這裡不再描述,你可以參考以下的圖形:

1 1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

input

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

output

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

sample input

2 3

sample output

1 1 1

1 1 1

1 2 1

#include

#include

#include

#include

using

namespace

std;

main()

; a[1][1]=1;

a[2][1]=1;

a[2][2]=1;

for(int i=3;i<=30;i++)

}

int n;

while(scanf("%d",&n)!=eof)

printf("\n");

}printf("\n");

}}

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...

輸出楊輝三角

程式的版權和版本宣告部分 檔名稱 fibnacci.cpp 作 者 單虹毓 完成日期 2013 年 12 月 4 日 版本號 v1.0 輸入描述 無 問題描述 楊輝三角 程式輸出 1 第0列和對角線上的元素都為1。程式輸出 2 除第0列和對角線上的元素以外,其它元素的值均為前一行上的同列元素和前一列...