Leap Year Test

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Leap Year Test (/thread-9285.html)



Leap Year Test - Eddie W. Shore - 10-12-2017 08:36 PM

Introduction

The presented program tests whether a year is a leap year. A leap year has 366 days instead of 365, with the extra day given to February (February 29). The criteria for a leap year are:

* Leap years are year numbers evenly divisible by 4. Example: 1992, 2016
* Exception: years that are divisible by 100 but not divisible by 400. Example: 2000 is a leap year, but 1900 and 2100 aren’t.

HP Prime Program ISLEAPYEAR

Code:
EXPORT ISLEAPYEAR(y)
BEGIN
IF FP(y/4) ≠ 0 OR (FP(y/100) == 0 AND FP(y/400) ≠ 0)
THEN 
RETURN 0;
ELSE
RETURN 1;
END;
END;

Link to blog entry: http://edspi31415.blogspot.com/2017/10/hp-prime-and-casio-fx-cg-50-leap-year.html


RE: Leap Year Test - Didier Lachieze - 10-13-2017 06:31 AM

Another way to do it on the Prime :
Code:
EXPORT ISLEAPYEAR(y)
BEGIN
DDAYS(y+0.0101,y+1.0101)==366;
END;