Write a function called fact that recursively calculates the factorial value of its single int parameter.

1
Write a function called fact that recursively calculates the factorial value of its single int parameter.

LANGUAGE: C++

CHALLENGE:

Write a function called  fact that recursively calculates the factorial value  of its single int parameter. The value  returned by  fact is a  long ..

SOLUTION:


long fact(int n) {
    if (n <= 1) {
        return 1;
    } else {
        return (fact(n-1) * (long) n);
    }
}

One comment

Add comment