c#杨辉三角问题
来源:百度知道 编辑:UC知道 时间:2024/09/21 07:01:20
using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
int x, y;
int[,] a = new int[6, 6];
for (x = 0; x <= 5; x++)
{
for (y = 0; y <= x; y++)
{
if (x == y || y == 0)
a[x, y] = 1;
else
a[x, y] = a[x - 1, y - 1] + a[x - 1, y];
Console.Write(a[x, y] + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
} 可以帮忙解释一下MAIN后面的每一条语句吗`?
本人比较笨```麻烦大家了`
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
int x, y;
int[,] a = new int[6, 6];
for (x = 0; x <= 5; x++)
{
for (y = 0; y <= x; y++)
{
if (x == y || y == 0)
a[x, y] = 1;
else
a[x, y] = a[x - 1, y - 1] + a[x - 1, y];
Console.Write(a[x, y] + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
} 可以帮忙解释一下MAIN后面的每一条语句吗`?
本人比较笨```麻烦大家了`
int x, y;
int[,] a = new int[6, 6];
//定义一个名称为a的6行6列数组
for (x = 0; x <= 5; x++)
//循环每一行
{
for (y = 0; y <= x; y++)
//循环每一列
{
if (x == y || y == 0)
//判断
a[x, y] = 1;
//赋值
else
//判断不成立时的赋值
a[x, y] = a[x - 1, y - 1] + a[x - 1, y];
Console.Write(a[x, y] + " ");
//输出单个数组的元素,后面加一个空格
}
Console.WriteLine();
//循环输出一列后,输出一个回车符,光标跳转到下一列
}
Console.ReadLine();
//保留屏幕