namespace 杨辉三角
{
class Program
{
static void Main(string[] args)
{
//软件技术2班
//作者B16
//完成日期2014.11.25
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("-------------杨辉三角--------------");
int[,] yanghuiTriangle = new int[11, 11];
for (int i = 0; i < yanghuiTriangle.GetLength(0); i++)
{
yanghuiTriangle[i, 0] = 1;
yanghuiTriangle[i,i]=1;
if(i>1)
{
for (int j = 1; j <i; j++)
{
yanghuiTriangle[i, j] = yanghuiTriangle[i - 1, j - 1] + yanghuiTriangle[i - 1, j];
}
}
}
for (int i = 0; i < yanghuiTriangle.GetLength(0); i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write("{0,-4}", yanghuiTriangle[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
{
class Program
{
static void Main(string[] args)
{
//软件技术2班
//作者B16
//完成日期2014.11.25
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("-------------杨辉三角--------------");
int[,] yanghuiTriangle = new int[11, 11];
for (int i = 0; i < yanghuiTriangle.GetLength(0); i++)
{
yanghuiTriangle[i, 0] = 1;
yanghuiTriangle[i,i]=1;
if(i>1)
{
for (int j = 1; j <i; j++)
{
yanghuiTriangle[i, j] = yanghuiTriangle[i - 1, j - 1] + yanghuiTriangle[i - 1, j];
}
}
}
for (int i = 0; i < yanghuiTriangle.GetLength(0); i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write("{0,-4}", yanghuiTriangle[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
兴趣还不错吧!
继续坚持!