Thursday, June 21, 2012

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

1 comment:

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

    ReplyDelete