C#交错数组打印杨辉三角
[cpp]
//C#基础知识难点,C#多出交错数组概念
//C#数组,System.Text.StringBuilder很强大的类功能!
//交错数组,打印杨辉三角形
using System;
class Test
{
public static void Main()
{
int i, j, k;
Console.WriteLine(“请输入你要打印的行数:”);
k=int.Parse(Console.ReadLine());
int[][] Y = new int[k][];
for (i = 0; i < Y.Length; i++)
{
Y[i] = new int[i + 1];
Y[i][0] = 1;
Y[i][i] = 1;
}
for (i = 2; i < Y.Length; i++)
for (j = 1; j < Y[i].Length – 1; j++)
Y[i][j] = Y[i – 1][j – 1] + Y[i – 1][j];
for (i = 0; i < Y.Length; i++)
{
for (j = 0; j < Y[i].Length; j++)
{
Console.Write(“{0,5:d}”, Y[i][j]);
}
Console.WriteLine();
}
}
}
[/cpp]