怎么打印出如下杨辉三角形?    1
  1 2 1
 1 3 3 1
1 4 6 4 1

解决方案 »

  1.   

    http://wzcsying.blog.51cto.com/284684/53767/
      

  2.   

    http://blog.csdn.net/linux7985/article/details/5987155多个方法实现杨辉三角形
      

  3.   

    http://wzcsying.blog.51cto.com/284684/53767/http://wzcsying.blog.51cto.com/284684/53767/
      

  4.   

    http://topic.csdn.net/u/20090530/17/393a6b38-10dd-4031-9093-03f7c8130072.html
      

  5.   

    我的面试题也差不多是用两个for循环做出来,
    ---*---
    -*-*-*-
    *-*-*-*
    -*-*-*-
    ---*---
    求大侠们指点下
      

  6.   

    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()));
                }
            }
        }
    }  1
      1   1
      1   2   1
      1   3   3   1
      1   4   6   4   1
      1   5  10  10   5   1
      1   6  15  20  15   6   1
      1   7  21  35  35  21   7   1
      1   8  28  56  70  56  28   8   1
    Press any key to continue . . .