% fac(N, F) is true when F is N factorial (N must be bound before calling).
% N should not be more than 12 or arithmetic overflow will result

fac(0, 1).

fac(N, F) :- N > 0,  N1 is N - 1,  fac(N1, F1),  F is N*F1.