class Shuzu
{
public static void Main(String[] args)
{
int n =Convert.ToInt32(Console.ReadLine());//从键盘输入杨辉三角的行数
int[] inlistold = new int[15];
int[] inlistnew = new int[15];
for (int i = 1; i <= n; i++)//遍历每行并计算后输出
{
inlistnew.CopyTo(inlistold, 0);
Console.Write(" ");
for (int x = 1; x <= (n - i); x++)
{
Console.Write(" ");
}
for (int j = 1; j <= i; j++)
{
if (j == 1 || j == i)
{
inlistnew[j] = 1;
Console.Write(" 1 ");
}
else
{
int jisuan = inlistold[j] + inlistold[j - 1];
inlistnew[j] = jisuan;
if (jisuan < 10)
{
Console.Write(" " + jisuan + " ");
}
else
{
Console.Write(" " + jisuan);
}
}
Console.Write(" ");
}
Console.WriteLine("");
}
}
} |