Jan 29, 2010

factorial of any number

Q1. Write a program to find the factorial of any number. Test it with 11.

Code:
Predicates
factorial(integer,integer)
Clauses
factorial(0,1).
factorial(N,F):-N>0,N1=N-1,factorial(N1,F1),F=N*F1.
Goal
factorial(11,F).

1 comment: