using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int [][] Array_int = new int[10][];
//遍历行数
for (int i = 0; i < Array_int.Length; i++ )
{
//定义二维数组的列数
Array_int[i] = new int[i+1];
//遍历列数
for (int j = 0; j < Array_int[i].Length;j++ )
{
//数组的前两行
if(i <= 1)
{
Array_int[i][j] = 1;
continue;
}
else
{
//行首或行尾
if(j == 0 || j == Array_int[i].Length - 1)
{
Array_int[i][j] = 1;
continue;
}
else
{
Array_int[i][j] = Array_int[i-1][j-1] + Array_int[i - 1][j];
}
}
}
}
//打印
for (int i = 0; i < Array_int.Length; i++)
{
for (int j = 0; j < Array_int[i].Length; j++)
{
Console.Write("{0}\t", Array_int[i][j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
杨辉三角
最新推荐文章于 2022-05-29 23:00:00 发布
5万+

被折叠的 条评论
为什么被折叠?



