码迷,mamicode.com
首页 > 其他好文 > 详细

Pascal's triangle

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

标签:style   blog   http   color   for   2014   div   sp   log   

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

标签:style   blog   http   color   for   2014   div   sp   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!