番茄零乱初学C#之杨辉三角

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

namespace PascalTriangle
{
    class Program
    {
        static void Main(string[] args)
        {
            PT(new int[1]{1});
        }
       static int[] PT(int[] num)
        {
            Console.Write("\n{0}", new string(' ', (10- num.Length)*2));
            foreach (int j in num)
            {
                Console.Write("{0,-4}",j);
            }
            
            if (num.Length == 10)
                return num;
            int[] n = new int[num.Length + 1];
            n[0] = n[n.Length - 1] = 1;
            for (int i = 1; i <=num.Length - 1; i++)
            {
                n[i] = num[i - 1] + num[i];
            }
            return PT(n);
        }
    }
}

posted @ 2010-12-08 18:52  番茄零乱  阅读(275)  评论(1编辑  收藏  举报