Sign in

gwj / po_oopc · Files

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Network
  • Graphs
  • po_oopc
  • examples12
  • factorial.cpp
  • Reformatted code
    c0b14c54
    Grzegorz Jabłoński authored
    2022-09-16 14:36:36 +0200  
    Browse Code »
factorial.cpp 343 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
using namespace std;

template <int N> constexpr int factorial()
{
    return N * factorial<N - 1>();
}

template <> constexpr int factorial<0>()
{
    return 1;
}

constexpr int fact2(int n)
{
    if (n > 0)
        return n * fact2(n - 1);
    else
        return 1;
}

int main()
{
    cout << factorial<7>() << endl;
}