problem description
還記得中學時候學過的楊輝三角嗎?具體的定義這裡不再描述,你可以參考以下的圖形: 1
1 11 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
11 11
1 11 2 1
author
lcysource
c語言程式設計練習(五)
c語言ac**
#includeint main()
for(i=3;i<=n;i++)
for(j=2;j
再加乙個優化版的**,有沒有雞腿呀:)
#include main()
; while(scanf("%d",&n)!=eof)
{for(i=1; i<=n; i++)
{for(j=1; j<=i; j++)
{a[i][j]=a[i-1][j-1]+a[i-1][j]; /*每個數是上面兩數之和*/
printf("%d",a[i][j]); /*輸出楊輝三角*/
if(j#include int main()
{ int n,count=1,i,a[34];
while(scanf("%d",&n)!=eof)
{a[0]=1;
printf("%d\n",a[0]);
for(i=1; i=1; count--)
a[count]=a[count]+a[count-1];
for(count=0; count<=i; count++)
{printf("%d",a[count]);
if(count
HDU2032 楊輝三角
problem description 還記得中學時候學過的楊輝三角嗎?具體的定義這裡不再描述,你可以參考以下的圖形 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 表示...
HDU2032楊輝三角
problem description 1 1 11 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 input 輸入資料報含多個測試例項,每個測試例項的輸入只包含乙個正整數n 1 n 30 表示將要輸出的楊輝三角的層數。output 對應於每乙個輸入,請輸出相應層數的楊輝三...
hdu 2032 楊輝三角
還記得中學時候學過的楊輝三角嗎?具體的定義這裡不再描述,你可以參考以下的圖形 1 1 11 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 input 輸入資料報含多個測試例項,每個測試例項的輸入只包含乙個正整數n 1 n 30 表示將要輸出的楊輝三角的層數。output 對...