You are currently viewing Program to calculate the factorial of a number in prolog.

Program to calculate the factorial of a number in prolog.

In previous article we have discussed about Prolog and how to make program in Prolog.

In the factorial program like take 5

  • Factorial of 5 is 120 as 5*4*3*2*1

PROGRAM:

fact(1,1).
fact(N,R):- N1 is N-1, fact(N1,R1), R is R1*N.

 

OUTPUT:

 

Dinesh Kumar Bansal

Dinesh Kumar Bansal is an Indian Software Developer, who is working on ASP.Net, MS-SQL, SAP-ABAP technologies from last one year. His Basic Principle of developing software is, “You have to clear about, what do you want to do, how can it be done”. He always says that development can be done with a cool & fresh mind.

Leave a Reply