杨辉三角形C#编程

  1. // Copyright (c) 2014软件技术1班  
  2. // All rights reserved.   
  3. // 作    者:20143313028 
  4. // 完成日期:2014年 11月 24 日   
  5. // 版 本 号:v1.0   
  6. //   
  7. // 问题描述:创建一个程序来生成杨辉三角形  
  8. // 输入描述:二维数组
  9. // 程序输出:杨辉三角形
  10. //通过这个问题让我懂得了如何运用二维数组解决问题
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[,] array = new int[11, 11];
                for (int i = 0; i < 11; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (j == 0 || j == i)
                        {
                            array[i, j] = 1;
                        }
                        else
                        {
                            array[i, j] = array[i - 1, j - 1] + array[i - 1, j];
                        }
                        Console.Write("{0}", array[i, j]);
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }
        }
    }
    

    《杨辉三角形C#编程》

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/whz1152919588/article/details/41443355
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞