// All rights reserved.
// 作 者:A22 黄鲜彩
// 完成日期:2014年 11 月 23 日
// 版 本 号:v1.0
//问题描述:对角线和每行的第1列均为1,其余各项是它的上一行中前一个元素和上一列元素之和。请编写程序,输出n=10的杨辉三角形(共11行)。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[11, 11];
for (int i = 0; i < 11; i++)
{
a[i, 0] = 1;
a[i, i] = 1;
}
for (int i = 2; i < 11; i++)
for (int j = 1; j < 11; j++)
{
a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
}
for (int i = 0; i < 11; i++)
{
Console .Write ("\n");
for (int j = 0; j <=i; j++)
{
Console.Write("{0} ", a[i, j]);
}
}
Console.ReadKey();
}
}
}
小结:通过此次的程序编写,学会了运用二维数组的知识来解决问题。