【算法基础】面试过程中遇到的一些算法题输出杨辉三角
输出杨辉三角
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var row = 8; var arry = new int[row, row]; for (int i = 0; i < row; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || i == j) { arry[i, j] = 1; } else { arry[i, j] = arry[i - 1, j - 1] + arry[i - 1, j]; } } } for (int i = 0; i < row; i++) { for (int j = 0; j <= i; j++) { Console.Write(arry[i, j].ToString().PadLeft(4, ' ')); } Console.WriteLine(); } } } }
效果