3. Write a program in PROLOG to implement factorial (N, F) where F represents the factorial of a number N.
% Write a program in PROLOG to implement factorial (N, F)
where F represents the factorial of a number N.
% below factorial function is not predefined you can use any name as function
factorial(0, 1).
factorial(N, X) :-
N > 0,
Y is N - 1,
factorial(Y, Z),
X is Z * N.
% Output
No comments:
Post a Comment