Sobes.tech
Intern — Middle

Compile-time factorial calculation using constexpr

livecode

Task condition

This is a recursive function that calculates the factorial of a number. It is required to rewrite it so that the result is obtained during compilation, using the capabilities of constexpr. You can change the names of parameters and variables, but keep the logic the same.

constexpr unsigned long long fact(unsigned int value) {
    return (value == 0) ? 1 : fact(value - 1) * value;
}