Mode:
Duration:
1
2
3
4
5
factorial(0,1).
factorial(N,F) :- N > 0, N1 is N-1, factorial(N1,F1), F is N * F1.
% Example
?- factorial(5,F), write(F), nl.Coding works best on desktop or with an external keyboard.
factorial(0,1).
factorial(N,F) :- N > 0, N1 is N-1, factorial(N1,F1), F is N * F1.
% Example
?- factorial(5,F), write(F), nl.Coding works best on desktop or with an external keyboard.
Calculates factorial using recursion.
factorial(0,1).
factorial(N,F) :- N > 0, N1 is N-1, factorial(N1,F1), F is N * F1.
% Example
?- factorial(5,F), write(F), nl.Prolog (Programming in Logic) is a high-level, declarative programming language focused on logic programming and symbolic reasoning. It is widely used in artificial intelligence, natural language processing, and rule-based systems, enabling developers to express knowledge and relationships rather than step-by-step instructions.
Origin & Creator
Developed in 1972 by Alain Colmerauer and Robert Kowalski at the University of Marseille.
Industrial Note
Prolog underpins many AI applications, including expert systems, natural language understanding, and theorem proving frameworks.