杨辉三角算法实现
static void YangHui(int n) { var arr = new int[n,n]; for (var i = 0; i < n; i++) { Console.Write("".PadLeft(n-i)); for (var j = 0; j <= i; j++) { if (i == j||j==0) { arr[i,j] = 1; } else if (i > 0 && j > 0) { arr[i,j] = arr[i - 1,j - 1] + arr[i - 1,j]; } Console.Write(arr[i, j] + " "); } Console.WriteLine(); } }
转载时请注明出处!