[ create a new paste ] login | about

Link: http://codepad.org/6OUn51fD    [ raw code | output | fork ]

C++, pasted on Jun 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

template <int N>
class Factorial {
public:
    enum { Result = N * Factorial<N - 1>::Result };
};
 
template <>
class Factorial<0> {
public:
    enum { Result = 1 };
};

int main() {

	std::cout << Factorial<5>::Result << std::endl;
	return 0;
}
 


Output:
1
120


Create a new paste based on this one


Comments: