Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to find factorial of given number

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 16108

Prolog program to find factorial of given number.

Code for Prolog program to find factorial of given number in Artificial Intelligence

predicates
    start
    find_factorial(real,real)

goal
    clearwindow,
    start.

clauses
    start:-
        write("Enter non negative number = "),
        readreal(Num),
        Result = 1.0,
        find_factorial(Num,Result).

    find_factorial(Num,Result):-
        Num <> 0,
        NewResult = Num * Result,
        NewNum = Num - 1,
        find_factorial(NewNum,NewResult).
        
    find_factorial(_,Result):-
        write("Factorial = ",Result),nl.
        
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to find factorial of given number Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to find factorial of given number is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!