% Write a Prolog program to calculate the factorial of a given number.
fact(0,1). fact(N,F):- ( % The below is for +ve factorial. N>0 -> ( N1 is N-1, fact(N1,F1), F is N*F1 ) ;
% The below is for -ve factorial. N<0 -> ( N1 is N+1, fact(N1,F1), F is N*F1 ) ).
% Output
Prolog Factorial Program |
Video on prolog program to find the factorial of a number.
Nice Post! I couldn't even figure how to compile prolog code. You helped a lot!
ReplyDeletePlease look at the Output Image, where the command for compiling this Prolog Program is clearly written. Also, this and all the related posts assume that you have a minimum experience with Prolog. If not, you can always go and search for resources for the same on any Search Engine.
DeleteHope this helps.
Great information help us to understand how to write Prolog program to calculate the factorial of any number. Thanks for sharing.
ReplyDeleteBest Artificial Intelligence course in Mumbai