本文共 1519 字,大约阅读时间需要 5 分钟。
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(); } }}
转载地址:http://dteii.baihongyu.com/