C# 杨辉三角形算法

代码如下:

        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();

        }
    }
上一篇:[转] css选择器中:first-child与:first-of-type的区别


下一篇:利用numpy+matplotlib绘图的基本操作教程