Published on 11 October 2019 (Updated: 11 October 2019)

Welcome to the Factorial in Matlab page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

functionresult=factorial(n)ifn<0error('Please input a non-negative integer')endifnot(ischar(n))error('Please input a non-negative integer')endifisempty(n)=1error('Please input a non-negative integer')endx=1;ifn>0fori=1:nx=x*i;endendresult=xend

Note: The solution shown above is the current solution in the Sample Programs repository as of Oct 11 2019 20:10:31. The solution was first committed on Oct 11 2019 19:40:51. As a result, documentation below may be outdated.