Program of built-in factorial function:
Calling this function yields similar result as the built-in factorial function:
>> fact(5)
ans =
120
>> factorial(5)
ans =
120
The recursive factorial function is a very common illustration of a recursive function. It is somewhat of a lame illustration, though, as recursion is not essential to find a factorial; a for loop can be just used as well in the programming (or, obviously, the built-in function in MATLAB).