首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求好手写一个程序

2012-10-20 
求高手写一个程序!一个有交叉数组 写起来的杨辉三角 应该怎么写! 高手在哪里[解决办法]C# codeusing Syste

求高手写一个程序!
一个有交叉数组 写起来的杨辉三角 应该怎么写! 高手在哪里

[解决办法]

C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    static class Helper    {         //m!/(n!*(m-n)!)        public static int C(int m, int n)        {            return facEx(n + 1, m) / facEx(2, m - n);        }        private static int facEx(int from, int to)        {            int result = 1;            for (int i = from; i <= to; i++)            {                result *= i;            }            return result;        }    }    class Program    {        static void Main(string[] args)        {            int n = 8;            int[][] result = new int[n + 1][];            for (int i = 0; i < n + 1; i++)            {                result[i] = new int[i + 1];                for (int j = 0; j <= i; j++)                {                    result[i][j] = Helper.C(i, j);                }            }            foreach (int[] item in result)            {                Console.WriteLine(string.Join(" ", item.Select(x => x.ToString().PadLeft(3, ' ')).ToArray()));            }        }    }} 

热点排行