using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YangHuiSanJiao
{
class Program
{
static void Main(
string[] args)
{
Console.Write("请输入行数:");
int n =
int.Parse(Console.ReadLine());
int[][] Array_int=
new int[n][];
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;
else
{
Array_int[i][j] = Array_int[i -
1][j] + Array_int[i -
1][j -
1];
}
}
}
}
for (
int i =
0; i < Array_int.Length; i++
)
{
for (
int j =
0; j < Array_int[i].Length; j++
)
{
Console.Write("{0}\t\t",Array_int[i][j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
在遍历每一行的时候新建列数,每行的列数和行数一样。
第一行和第二行是1,每一行的第一行和最后一行是1
其他行的算法是A[i][j]=A[i-1][j]+A[i-1][j-1]
转载于:https://www.cnblogs.com/lovezhangyu/p/3368969.html
相关资源:C++杨辉三角