C#杨辉三角形

it2022-05-05  109

using System;using System.Collections.Generic;using System.Text;

namespace test1{    class Program    {        static void Main(string[] args)        {            int[][] arr = new int[10][];

            for (int i = 0; i < arr.Length; i++)            {                arr[i] = new int[i + 1];                for (int j = 0; j < arr[i].Length; j++)                {                    if (i <= 1)                    {                        arr[i][j] = 1;                        continue;                    }                    else                    {                        if (j == 0 || j == arr[i].Length - 1)                            arr[i][j] = 1;                        else                            arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];                    }                }            }            for (int i = 0; i < arr.Length; i++)            {                for (int j = 0; j < arr[i].Length; j++)                    Console.Write("{0}/t", arr[i][j]);                Console.Write("/n");            }            Console.ReadLine();        }

            }}

转载于:https://www.cnblogs.com/xxj-jing/archive/2008/11/09/2890122.html

相关资源:C# 杨辉三角 交错数组

最新回复(0)