Write a program in PROLOG to implement factorial (N, F) where F represents the factorial of a number N.

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

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...