**Find the Factorial of a number**

predicates go fact(integer,integer) clauses go:- write("give the no:"), readint(X), Z=1, fact(X,Z). fact(1,Z):- write("the result:",Z). fact(X,Z):- Y=Z*X, XX=X-1, fact(XX,Y).

Skip to content
# Prolog program to find the Factorial of a number

**Find the Factorial of a number**
##
2 thoughts on “Prolog program to find the Factorial of a number”

### Leave a Reply

predicates go fact(integer,integer) clauses go:- write("give the no:"), readint(X), Z=1, fact(X,Z). fact(1,Z):- write("the result:",Z). fact(X,Z):- Y=Z*X, XX=X-1, fact(XX,Y).

%d bloggers like this:

What about if we have the factorial of a number and we want to find in which number it belongs? For example i have 120 and want prolog to tell me that 120 is the factorial of 5.

thanks ^ ^