Thursday, June 21, 2012

Prolog program to find Factorial of an Integer

PREDICATES
factorial(integer, integer)

CLAUSES
factorial(0,1).
factorial(X,Y):-
X<>0, S=X-1, factorial(S,Y1), Y=X*Y1.

GOAL
write("The value of Z is "),
factorial(5,Z).

No comments:

Post a Comment