using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 杨辉三角
{
class Program
{
static void Main(string[] args)
{
//定义数组
int[,] a = new int[10, 10];
//处理
for (int i = 0; i <a.GetLength(0); i++)
{
for (int j = 0; j <a.GetLength(1); j++)
{
if (j == 0 || j == i) a[i, j] = 1;
if (i >= 2&&j>0) a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
}
}
//输出
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
if(a[i,j]!=0)
Console.Write("{0}\t",a[i,j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
杨辉三角
最新推荐文章于 2024-03-17 18:00:07 发布