C# 杨辉三角

来源:百度知道 编辑:UC知道 时间:2024/08/20 15:48:32
按如下格式打印杨辉三角
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1

注意:是用windows应用程序做,数组与字符串的内容,高手指教。
貌似不对嘛,在windows应用程序中说不对,或者各位高人们直接把程序做出来解压后发我邮箱里,271155275@qq.com,小弟在此感激不尽。

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();

}
}
}

不用要程序吧,这个很简单的,你建个控制台程序全部copy进去就好了

代码我是照课本打的,这学期都不学了。
我用的VISTA不支持一般的C#编译器,做不了。

using System;
class text{
public staticvoid Main(){
int[,]a=new int[9,9];
a[0