Prolog program to find factorial of a given number

Prolog program to find factorial of a given number.

factorial of a given number

Program:

fact(X,Y):-X is  0,Y is 1;
  X>0,N is X-1, fact(N,G),Y is X*G.

Output:
?- fact(3,X).
X=6.

?- fact(5,X).
X=120.

Comments