12

Formula: n! = n × (n-1) × ... × 1, and 0! = 1.

Example: 5! = 120

Solution 1: Loop O(n) C++ 5 lines
int n = 5;
long long fact = 1;
for(int i = 1; i <= n; i++)
    fact *= i;
cout << fact; // 120
Solution 2: Recursion C++ 4 lines
long long fact(int n){
    if(n <= 1) return 1;
    return n * fact(n - 1);
}

Note: 20! is the largest factorial that fits in long long.