var a = new int[5, 5];
for (int i = 0; i < a.GetLength(0); i++)
{
a[i,0] = 1;
}
for (int i = 1; i <a.GetLength(0); i++)
{
for (int j = 1; j < a.GetLength(1); j++)
{
a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
}
}
for (int i = 0; i < a.GetLength(0); i++)
{
for (int k = 1; k <=4-i; k++)
{
Console.Write("\t");
}
for (int j = 0; j <=i; j++)
{
Console.Write(a[i, j]+"\t\t");
}
Console.WriteLine();
}
Console.ReadKey();
网友评论