Advertisement
bogolyubskiyalexey

template factorial

Feb 22nd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. template <int n>
  5. struct Factorial {
  6.     static int Value() {
  7.         return Factorial<n - 1>::Value() * n;
  8.     }
  9. };
  10.  
  11. template<>
  12. struct Factorial<1> {
  13.     static int Value() {
  14.         return 1;
  15.     }
  16. };
  17.  
  18. int main() {
  19.     std::cout << Factorial<3>::Value() << std::endl;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement