import java.util.Scanner;
public class yanghui
{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("\nPlease enter the number of Yang Hui triangle rows:");
int n=sc.nextInt();
int [][]a=new int [n][];
for(int i=0;i<n;i++){
a[i]=new int[i+1];//Determine the length of each one-dimensional array.
for(int j=0;j<=i;j++){
if(j==0)
a[i][j]=1;
if(i==j)
a[i][j]=1;
}}
for(int i=2;i<n;i++){
for(int j=1;j<i;j++){
a[i][j]=a[i-1][j]+a[i-1][j-1];
}}
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
System.out.printf("\t"+a[i][j]);
}
System.out.println();
}
}}
原文地址:https://www.cnblogs.com/wxh-blog/p/10684212.html
时间: 2024-11-06 10:32:06