c#杨辉三角

  

 const int length = 8;

            var a = new int[length][];
            for (var i = 0; i < a.Length; i++)
            {
                a[i] = new int[i + 1];
            }

            for (var j = 0; j < a.Length; j++)
            {
                a[j][0] = 1;
                a[j][j] = 1;
                for (var m = 1; m < a[j].Length - 1; m++)
                {
                    a[j][m] = a[j - 1][m - 1] + a[j - 1][m];
                }

            }
            foreach (var t in a)
            {
                foreach (var t1 in t)
                {
                    Console.Write("{0}\t",t1);
                }
                Console.Write("\n");
            }
            Console.Read();

 

posted @ 2015-11-03 00:17  objnet  阅读(219)  评论(0编辑  收藏  举报