c# 打印杨辉三角二维不规则数组

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3_打印杨辉三角_二维不规则数组_
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = 9;
            int[][] a = new int[k][];  //定义二维不规则数组
            for (int i = 0; i < a.Length; i++)
                a[i] = new int[i + 1];
            for(int j = 0; j < a.Length; j++)
            {
                a[j][0] = 1;
                a[j][a[j].Length - 1] = 1;
                for (int m = 1; m < a[j].Length - 1; m++)
                    a[j][m] = a[j - 1][m - 1] + a[j - 1][m];
            }
            for(int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < a[i].Length; j++)
                    Console.Write("{0}\t",a[i][j]);
                Console.WriteLine();
            }
        }
    }
}

相关文章

1 在Visual Studio 中创建一个Asp.NET WebApi 项目,项目名:...
using ImpromptuInterface; using System; using System.Dyn...
https://blog.csdn.net/michaelgong/article/details/431485...
C#11添加了文件作用域类型功能:一个新的file修饰符,可以应...
在.NET中Newtonsoft.Json(Json.NET)是我们常用来进行Json序列...
设置允许跨域访问的网址--&gt; 设置预检有效时间--&...