您的位置:首页 > 其它

杨辉三角

2017-01-20 16:05 253 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: