首页 > 其他 > 详细

Pascal's triangle

时间:2014-09-04 16:29:29      阅读:290      评论:0      收藏:0      [点我收藏+]

Pascal‘s triangle is one of a well known angle. You can have a better understand through the img below.

bubuko.com,布布扣  bubuko.com,布布扣

 

#include "stdafx.h"


long pascals_fun(int row, int col)
{
    if(row == 1 || col == 1 || col == row)
        return 1;
    else 
        return pascals_fun(row - 1, col -1) + pascals_fun(row - 1, col);
}

int main() {
    int n = 20;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i + 1; j++) {
            printf("%d ", pascals_fun(i + 1, j + 1));
        }
        printf("\n");
    }
    return 0;
}

 

Pascal's triangle

原文:http://www.cnblogs.com/jacobhe/p/3956218.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!