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

SHARE Prolog program to find Factorial of an Integer

You may also like...

1 Response

  1. Unknown says:

    compiling /home/jdoodle.pg for byte code…
    /home/jdoodle.pg:2:1: syntax error: . or operator expected after expression
    /home/jdoodle.pg:7:2: syntax error: . or operator expected after expression
    /home/jdoodle.pg:10:1: syntax error: . or operator expected after expression
    3 error(s)
    compilation failed
    | ?-
    uncaught exception: error(syntax_error('user_input:4 (char:1) . or operator expected after expression'),read_term/3)
    | ?-

Leave a Reply

Your email address will not be published.

Share