Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to check whether a number is a member of given list or not

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

Prolog program to check whether a number is a member of given list or not.

Code for Prolog program to check whether a number is a member of given list or not in Artificial Intelligence

domains

    list=integer*

    
predicates

    findnum(integer,list)

    
clauses

    findnum(X,[]):-
        write("\nNumber Is Not Found").

    findnum(X,[X|Tail]):-
        write("\nNumber Is Found").            

    findnum(X,[Y|Tail]):-
        findnum(X,Tail).
        

OUT PUT
=======

Goal: findnum(3,[1,2,3,4,5])

Number Is Found

Yes

----------------------------

Goal: findnum(6,[1,2,3,4,5])

Number Is Not Found

Yes

----------------------------

Goal: findnum(2,[1,2,2,1])

Number Is Found

Yes
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to check whether a number is a member of given list or not 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!