杨辉三角版本2

来源:互联网 发布:串口接收数据原理 编辑:程序博客网 时间:2024/05/29 10:04
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication3{    class Program    {        static void Main(string[] args)        {            int[,] number = new int[11, 11];            for (int i = 0; i < number.GetLength(0); i++)            {                for (int j = 0; j < number.GetLength(1); j++)                {                    if (i == j || j == 0) number[i, j] = 1;                    else if (i != 0) number[i, j] = number[i - 1, j - 1] + number[i - 1, j];                    else number[i, j] = 0;                }            }            for (int i = 0; i < number.GetLength(0); i++)            {                for (int j = 0; j < number.GetLength(1); j++)                {                   if(number[i,j]==0)  Console.Write(" ");                   else Console.Write("{0}  ",number[i,j]);                }                Console.WriteLine();            }            Console.ReadKey();        }    }}


0 0
原创粉丝点击