Sunday, 13 May 2012

Write a prolog program to find factorial of a number.


domains
num,f= integer
predicates
fact(num,f)
clauses
fact(0,1).
fact(X,F) if fact(X1,F1) and X=X1+1 and F=X*F1.
goal
write("Number: ") ,readint(X),fact(X,F),write("X!="),
write(F).

0 comments

 
© 2011-2012 ProgrammingBlue
Posts RSS Comments RSS
Back to top