不用循环控制、条件控制、三目运算符 实现阶乘n!

long func(int n)
{
    ( n <= 1 && (n=1) ) || ( n*=func(n-1));
    return n;
}
template<int N>
struct Factorial
{
    enum { Value = N * Factorial<N - 1>::Value };
};

template<>
struct Factorial<1>
{
    enum { Value = 1 };
};

猜你喜欢

转载自www.cnblogs.com/s3320/p/11812565.html
今日推荐