编程实践5-8
编程实践5-8
课程元素类型 任务
杨辉三角
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sj_5_8 { class Program { static void Main(string[] args) { int[,] iA = new int[10, 10]; for (int i = 0; i < iA.GetLength(0); i++) { iA[i, 0] = 1; iA[i, i] = 1; } for (int i = 2; i < iA.GetLength(0); i++) { for (int j = 1; j <= i; j++) { iA[i, j] = iA[i - 1, j - 1] + iA[i - 1, j]; } } for (int i = 0; i < iA.GetLength(0); i++) { for (int j = 0; j <= i; j++) { Console.Write("{0,-4}", iA[i, j]); } Console.WriteLine(); } Console.ReadKey(true); } } }