Factorial in MATLAB

Example for versions GNU Octave 3.2.3

This example uses recursive factorial definition.

function f = fact(n)
  if (n <= 1)
    f = 1;
  else
    f = n * fact(n - 1);
  endif
endfunction

for i = 0 : 16
  printf("%d! = %d\n", i, fact(i));
endfor