代码如下:
static void Main(string[] args) { int[][] Array_int = new int[10][]; //向数组中记录杨辉三角形的值 for (int i = 0; i < Array_int.Length; i++) { Array_int[i] = new int[i + 1]; for (int j = 0; j < Array_int[i].Length; j++) { if (i <= 1) { Array_int[i][j] = 1; continue; } else { if (j == 0 || j == Array_int[i].Length - 1) Array_int[i][j] = 1; else Array_int[i][j] = Array_int[i - 1][j - 1] + Array_int[i - 1][j]; } } } for (int i = 0; i < Array_int.Length; i++) { for (int j = 0; j < Array_int[i].Length; j++) Console.WriteLine("{0}\t", Array_int[i][j]); Console.WriteLine(); } Console.ReadLine(); } }