經典演算法-(三)帕斯卡三角形(楊輝三角形)

來源:互聯網
上載者:User

標籤:close   之一   images   結合   排列   i++   item   code   幾何   

楊輝三角,是二項式係數在三角形中的一種幾何排列。在歐洲,這個表叫做帕斯卡三角形。帕斯卡(1623----1662)是在1654年發現這一規律的,比楊輝要遲393年,比賈憲遲600年。

簡介:

楊輝三角,是二項式係數在三角形中的一種幾何排列。在歐洲,這個表叫做帕斯卡三角形。帕斯卡(1623----1662)是在1654年發現這一規律的,比楊輝要遲393年,比賈憲遲600年。楊輝三角是中國古代數學的傑出研究成果之一,它把二項式係數圖形化,把組合數內在的一些代數性質直觀地從圖形中體現出來,是一種離散型的數與形的優美結合

結果:(由於有兩位元和一位元的原因,排列看起來有點不規則)

 

 

java實現:

package a;import java.math.BigInteger;import java.util.*;public class Main{         public static  void main(String[] args)  {          System.out.println("請輸入n");        Scanner cin = new Scanner(System.in);               while(cin.hasNext()){            int n=cin.nextInt();            int[][] a=new int[n+1][n+1];            for(int i=0;i<n;i++) {                for(int k=0;k<n-i;k++) {                    System.out.print("  ");                    }                for(int j=0;j<i+1;j++) {                    if(j==0||j==n-1) {                        a[i][j]=1;                    }                    else {                        a[i][j]=a[i-1][j-1]+a[i-1][j];                    }                                        System.out.print(a[i][j]+"  ");                }                    System.out.println();            }         }        cin.close();            }}

 

經典演算法-(三)帕斯卡三角形(楊輝三角形)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.