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).
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).
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 ^ ^