Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to check whether a year is a leap year or not

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

Prolog program to check whether a year is a leap year or not.

Code for Prolog program to check whether a year is a leap year or not in Artificial Intelligence

domains
    year = integer   
    
predicates
    leap_check(year)
    check(year)

clauses
    leap_check(Year) :-
        Year mod 4 = 0,
        Year mod 100 = 0,
        Year mod 400 = 0.
        
    leap_check(Year) :-
        Year mod 4 = 0,
        Year mod 100 <> 0.

    check(Year) :-
        Year < 0,!,
        write("Year cannot be negative"),nl.
                
    check(Year) :-
        leap_check(Year),
        write(Year , " is a leap year"),nl.
        
    check(Year) :-
        write(Year , " is not a leap year"),nl.
        
Output :

Goal: check(2001)
2001 is not a leap year
Yes

Goal: check(2000)
2000 is a leap year
Yes

Goal: check(1900)
1900 is not a leap year
Yes

Goal: check(-9)
Year cannot be negative
Yes
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to check whether a year is a leap year or not is from India.
 
View All Articles

Related Articles and Code:


 
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!