zoukankan      html  css  js  c++  java
  • 面试题目-杨辉三角

     1 ///////////////////////////////////////////////////////////////////////////////
     2 //
     3 //  FileName    :   pascaltriangle.c
     4 //  Version     :   0.10
     5 //  Author      :   Ryan Han
     6 //  Date        :   2013/07/01 11:25:30
     7 //  Comment     :  
     8 //
     9 ///////////////////////////////////////////////////////////////////////////////
    10 #include <stdio.h>
    11 static long GetElement(const long row, const long col)
    12 {
    13     //1
    14     //1   1
    15     //1   2   1
    16     //1   3   3   1
    17     //1   4   6   4   1
    18 
    19     if(1 == col || col == row)
    20         return 1;
    21     else
    22         return GetElement(row - 1, col - 1) + GetElement(row - 1, col);
    23 }
    24 
    25 static long PascalTriangle(const long n)
    26 {
    27     int row, col;
    28     
    29     for(row = 1; row <= n; ++row)
    30     {
    31         for(col = 1; col <= row; ++col)
    32             printf("%4ld", GetElement(row, col));
    33         printf("
    ");
    34     }
    35 }
    36 
    37 int main()
    38 {
    39     PascalTriangle(5);
    40 }
  • 相关阅读:
    优化--工具
    架构
    Gradle
    战争迷雾
    进度管理
    工具
    架构
    牛人
    apk 破解
    效率
  • 原文地址:https://www.cnblogs.com/dracohan/p/3164684.html
Copyright © 2011-2022 走看看