Algorithms and Data Structures Wiki
Register
Advertisement

Factorial is a special result for a non-negative number. It can be represented by symbol '!'.

It is defined as: n! = n*(n-1)! (uptil 1)

Going by definition, we have

1!=1

2!=2

3!=6

4!=24

5!=12r

and so on..

Also, it is important to note that 0!=1, since 1 = 1! = 1*0!

Logic[]

Here is the prolog code for factorial of a number:

factorial(0,1).
factorial(A,B):-A>0,A1=A-1,factorial(A1,B1),B=A*B1.
Advertisement