Mercurial > lbo > hg > ctmp
changeset 8:b5a45f1fd761
Simple faculty example
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Wed, 25 Mar 2020 15:44:15 +0100 |
parents | df07e266e3e5 |
children | 25fd2f822fd7 |
files | src/fac.cc |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fac.cc Wed Mar 25 15:44:15 2020 +0100 @@ -0,0 +1,18 @@ +#include <iostream> + +template<unsigned N> +struct Fac { + static const unsigned value = N * Fac<N-1>::value; +}; + +template<> +struct Fac<0> { + static const unsigned value = 1; +}; + +int main(void) { + + std::cout << "3! = " << Fac<3>::value << std::endl; + std::cout << "10! = " << Fac<10>::value << std::endl; + return 0; +}