110,534
社区成员
发帖
与我相关
我的任务
分享
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()));
}
}
}
}