Aim: Write a Prolog program to find factorial of a given number.
Prolog Program Code:
predicates
fact(integer,integer)
fact(integer)
clauses
fact(0,X):-X=1.
fact(N,X):-NN=N-1,fact(NN,X1),X=X1*N.
fact(N):-fact(N,X),write(X).
predicates
fact(integer,integer)
fact(integer)
clauses
fact(0,X):-X=1.
fact(N,X):-NN=N-1,fact(NN,X1),X=X1*N.
fact(N):-fact(N,X),write(X).
0 Comments