using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
    class Program
    {
        int JieChen(int m)            //m的阶乘
        {
            int Res=1;   //阶乘的结果
            while (m != 0)
            {
                Res *= m;
                m--;
            }
            return Res;
        }
        static void Main()
        {
            Program P = new Program();
            int a = 1;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (i == 0)
                    {
                        Console.Write(a.ToString().PadLeft(7 - i));       //特殊格式输出
                    }
                    else
                    {
                        a = P.JieChen(i) / (P.JieChen(i - j) * P.JieChen(j));
                        if (j == 0)
                        {
                            Console.Write(a.ToString().PadLeft(7 - i));
                        }
                        else
                        {
                            Console.Write(a.ToString().PadLeft(2));
                        }
                    }
                  
                }
                Console.WriteLine();
            }
        }
    }
}


本文转载:CSDN博客