杨辉三角(pascal's triangle)

来源:互联网 发布:手机上怎样装修淘宝 编辑:程序博客网 时间:2024/05/22 02:19

输入行数,输出对应的杨辉三角

本题所用:
C(n,0)=1
C(n,k)=C(n,k-1)*(n-k+1)/k

运行结果如下:
运行结果

//输入行数,输出对应的杨辉三角#include <iostream>#include <cstdlib>#include <vector>using namespace std;int main() {    int n;    std::cin >> n;    for (int i = 0; i < n; i++) {        vector<int> v(i + 1);        v[0] = 1;        cout << v[0] << " ";        for (int j = 1; j <= i; j++) {            v[j] = v[j - 1] * (i - j + 1) / j;            cout << v[j]<<" ";        }        cout << endl;    }    return EXIT_FAILURE;}

附常用排列组合公式:
二项式定理(binomial theorem)

常用排列组合公式

原创粉丝点击