杨辉三角 二项式 阶乘

#include<iostream>
#include<algorithm>
using namespace std;
long long f(int n,int r)
{
    int k;
    long long s=1,t=1;
    for(k=n;k>=n-r+1;k--)
        s=s*k;
    for(k=1;k<=r;k++)
        t=t*k;
    return s/t;
}
int main()
{
    int n,k=0;
    long long a[26];
    while(cin>>n)
    {
        printf("Case %d: n=%d
",++k,n);
        n++;
        for(int i=1;i<=(n+1)/2;i++)
        { 
            a[i]=f(n-1,i-1);
            cout<<a[i]<<' ';
        }
        for(int i=n/2;i>1;i--)
        {
            cout<<a[i]<<' ';
        }
        cout<<a[1]<<endl;
 
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zxff/p/5947283.html