博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
阶乘、阶乘之和的函数式风格实现
阅读量:4080 次
发布时间:2019-05-25

本文共 601 字,大约阅读时间需要 2 分钟。

#include 
template
class Factorial{public: static int const vl = N * Factorial
::vl;};template<> class Factorial<1>{public: static int const vl = 1;};template
class FactorialSum{public: static int const vl = Factorial
::vl + FactorialSum
::vl;};template<> class FactorialSum<1>{public: static int const vl = Factorial<1>::vl;};void main(){ int const N = 7; printf("%d的阶乘:%d\n", N, Factorial
::vl); printf("%d的阶乘之和:%d\n", N, FactorialSum
::vl);}

参考:http://www.cnblogs.com/winter-cn/archive/2009/09/05/1561094.html

你可能感兴趣的文章