【C#输出杨辉三角】求大神如何将这段代码改成输出金字塔形的?实在想不到了。求大神
刚刚学C#,实在想不明白怎么把直角输出成 金字塔形式了。。。希望大神讲解 教导一下! 小弟在这里谢过了!!!
static void Main(string[] args)
{
Console.WriteLine("请输入自己想要的行数,记得要比你想要的大1哦!");
int line = Convert.ToInt32(Console.ReadLine());
int[][] sum = new int[line][];
string output = "";
for (int single = 0; single < sum.Length; single++)
{
string once = "";
sum[single] = new int[single];
for (int row = 0; row < single; row++)
{
if (row == 0 || row == sum[single].Length - 1)
{
sum[single][row] = 1;
}
else
{
sum[single][row] = sum[single - 1][row - 1] + sum[single - 1][row];
}
once = once + sum[single][row] + " ";
}
output = output + once + "\n";
}
Console.WriteLine(output);
Console.ReadKey();