Leap year: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 12: Line 12:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F is_leap_year(year)
<syntaxhighlight lang="11l">F is_leap_year(year)
I year % 100 == 0
I year % 100 == 0
R year % 400 == 0
R year % 400 == 0
R year % 4 == 0</lang>
R year % 4 == 0</syntaxhighlight>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
Line 27: Line 27:
When R15 = zero, the year is a leap year.
When R15 = zero, the year is a leap year.
Otherwise it is not.
Otherwise it is not.
<lang 360 Assembly>
<syntaxhighlight lang="360 assembly">
LPCK CSECT
LPCK CSECT
USING LPCK,15
USING LPCK,15
Line 46: Line 46:
BR 14
BR 14
END
END
</lang>
</syntaxhighlight>


Sample invocation from a COBOL program:
Sample invocation from a COBOL program:
Line 72: Line 72:
=={{header|68000 Assembly}}==
=={{header|68000 Assembly}}==


<lang 68000 Assembly>;Example
<syntaxhighlight lang="68000 assembly">;Example
move.l #2018,d0
move.l #2018,d0
bsr leap_year
bsr leap_year
Line 116: Line 116:
moveq.l #0,d1
moveq.l #0,d1
rts
rts
</syntaxhighlight>
</lang>


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==


<lang 8080asm> org 100h
<syntaxhighlight lang="8080asm"> org 100h
jmp test
jmp test
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 180: Line 180:
jmp 5
jmp 5
no: db 'NOT '
no: db 'NOT '
yes: db 'LEAP YEAR.$'</lang>
yes: db 'LEAP YEAR.$'</syntaxhighlight>




=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>BYTE FUNC IsLeapYear(CARD year)
<syntaxhighlight lang="action!">BYTE FUNC IsLeapYear(CARD year)
IF year MOD 100=0 THEN
IF year MOD 100=0 THEN
IF year MOD 400=0 THEN
IF year MOD 400=0 THEN
Line 213: Line 213:
FI
FI
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Leap_year.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Leap_year.png Screenshot from Atari 8-bit computer]
Line 227: Line 227:


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<lang actionscript>public function isLeapYear(year:int):Boolean {
<syntaxhighlight lang="actionscript">public function isLeapYear(year:int):Boolean {
if (year % 100 == 0) {
if (year % 100 == 0) {
return (year % 400 == 0);
return (year % 400 == 0);
}
}
return (year % 4 == 0);
return (year % 4 == 0);
}</lang>
}</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>-- Incomplete code, just a sniplet to do the task. Can be used in any package or method.
<syntaxhighlight lang="ada">-- Incomplete code, just a sniplet to do the task. Can be used in any package or method.
-- Adjust the type of Year if you use a different one.
-- Adjust the type of Year if you use a different one.
function Is_Leap_Year (Year : Integer) return Boolean is
function Is_Leap_Year (Year : Integer) return Boolean is
Line 269: Line 269:


-- To improve speed a bit more, use with
-- To improve speed a bit more, use with
pragma Inline (Is_Leap_Year);</lang>
pragma Inline (Is_Leap_Year);</syntaxhighlight>


=={{header|ALGOL 60}}==
=={{header|ALGOL 60}}==
{{works with|A60}}
{{works with|A60}}
<lang algol60>begin
<syntaxhighlight lang="algol60">begin
integer year;
integer year;


Line 286: Line 286:
if isLeapYear(year) then outstring(1,"True\n") else outstring(1, "False\n")
if isLeapYear(year) then outstring(1,"True\n") else outstring(1, "False\n")
end for year
end for year
end </lang>
end </syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 308: Line 308:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format''ted transput}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format''ted transput}}
<lang algol68>MODE YEAR = INT, MONTH = INT, DAY = INT;
<syntaxhighlight lang="algol68">MODE YEAR = INT, MONTH = INT, DAY = INT;
PROC year days = (YEAR year)DAY: # Ignore 1752 CE for the moment #
PROC year days = (YEAR year)DAY: # Ignore 1752 CE for the moment #
Line 326: Line 326:
printf(($g(0)" is "b("","not ")"a leap year."l$, year, is leap year(year)))
printf(($g(0)" is "b("","not ")"a leap year."l$, year, is leap year(year)))
OD
OD
)</lang>
)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 337: Line 337:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw>begin
<syntaxhighlight lang="algolw">begin
% returns true if year is a leap year, false otherwise %
% returns true if year is a leap year, false otherwise %
% assumes year is in the Gregorian Calendar %
% assumes year is in the Gregorian Calendar %
Line 352: Line 352:
)
)
end for_year
end for_year
end.</lang>
end.</syntaxhighlight>


=={{header|ALGOL-M}}==
=={{header|ALGOL-M}}==
<lang algol>
<syntaxhighlight lang="algol">
BEGIN
BEGIN


Line 399: Line 399:


END
END
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 424: Line 424:
=={{header|APL}}==
=={{header|APL}}==
Returns 1 if leap year, 0 otherwise:
Returns 1 if leap year, 0 otherwise:
<lang apl>
<syntaxhighlight lang="apl">
∇ z←Leap year
∇ z←Leap year
Z←(0=4|year)∧(0=400|year)∨~0=100|year
Z←(0=4|year)∧(0=400|year)∨~0=100|year
</syntaxhighlight>
</lang>
A much neater version of the above relies on the fact that every rule is an exception the the previous one:
A much neater version of the above relies on the fact that every rule is an exception the the previous one:
<lang apl>
<syntaxhighlight lang="apl">
∇ z←Leap year
∇ z←Leap year
z←0≠.=400 100 4∘.|year
z←0≠.=400 100 4∘.|year
</syntaxhighlight>
</lang>
This essentially works by running an XOR reduction over the divisibility by 4, 100, and 400. Some APL implementations support tacit (a.k.a. points-free) programming:
This essentially works by running an XOR reduction over the divisibility by 4, 100, and 400. Some APL implementations support tacit (a.k.a. points-free) programming:
<lang apl>
<syntaxhighlight lang="apl">
Leap←0≠.=400 100 4∘.|⊢
Leap←0≠.=400 100 4∘.|⊢
</syntaxhighlight>
</lang>
Dyalog APL version 18.0 added a built-in date-time function:
Dyalog APL version 18.0 added a built-in date-time function:
<lang apl>
<syntaxhighlight lang="apl">
Leap←0⎕DT,∘2 29¨
Leap←0⎕DT,∘2 29¨
</syntaxhighlight>
</lang>
This works by extending the year to February 29 of that year, and then checking if the date is valid.
This works by extending the year to February 29 of that year, and then checking if the date is valid.


With any of the above definitions, no loop is necessary to check each year of an array:
With any of the above definitions, no loop is necessary to check each year of an array:
<lang apl>
<syntaxhighlight lang="apl">
Leap 1899 1900 1901 1902 1903 1904 1905 1999 2000 2001 2002 2003 2004
Leap 1899 1900 1901 1902 1903 1904 1905 1999 2000 2001 2002 2003 2004
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<lang apl>
<syntaxhighlight lang="apl">
0 0 0 0 0 1 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 1 0 0 0 1
</syntaxhighlight>
</lang>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang applescript>on leap_year(y)
<syntaxhighlight lang="applescript">on leap_year(y)
return y mod 4 is equal to 0 and (y mod 100 is not equal to 0 or y mod 400 is equal to 0)
return y mod 4 is equal to 0 and (y mod 100 is not equal to 0 or y mod 400 is equal to 0)
end leap_year
end leap_year


leap_year(1900)</lang>
leap_year(1900)</syntaxhighlight>


=={{header|Arc}}==
=={{header|Arc}}==
<lang arc>
<syntaxhighlight lang="arc">
(= leap? (fn (year)
(= leap? (fn (year)
(if (and (is 0 (mod year 4)) (isnt 0 (mod year 100))) year
(if (and (is 0 (mod year 4)) (isnt 0 (mod year 100))) year
(unless (< 0 (+ (mod year 100) (mod year 400))) year))))
(unless (< 0 (+ (mod year 100) (mod year 400))) year))))
</syntaxhighlight>
</lang>
<b>Output:</b>
<b>Output:</b>
<lang arc>
<syntaxhighlight lang="arc">
(map [leap? _] '(1900 1904 2000 2019 2020 2100))
(map [leap? _] '(1900 1904 2000 2019 2020 2100))
;; => '( 1904 2000 2020 )
;; => '( 1904 2000 2020 )
</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>years: [
<syntaxhighlight lang="rebol">years: [
1600 1660 1724 1788 1848 1912 1972
1600 1660 1724 1788 1848 1912 1972
2032 2092 2156 2220 2280 2344 2348
2032 2092 2156 2220 2280 2344 2348
Line 481: Line 481:
]
]


print select years => leap?</lang>
print select years => leap?</syntaxhighlight>


{{out}}
{{out}}
Line 488: Line 488:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang autohotkey>leapyear(year)
<syntaxhighlight lang="autohotkey">leapyear(year)
{
{
if (Mod(year, 100) = 0)
if (Mod(year, 100) = 0)
Line 495: Line 495:
}
}


MsgBox, % leapyear(1604)</lang>
MsgBox, % leapyear(1604)</syntaxhighlight>
{{out}}
{{out}}
<pre>Returns 1 if year is a leap year</pre>
<pre>Returns 1 if year is a leap year</pre>
or
or
<lang autohotkey>IsLeapYear(Year)
<syntaxhighlight lang="autohotkey">IsLeapYear(Year)
{
{
return !Mod(Year, 4) && Mod(Year, 100) || !Mod(Year, 400)
return !Mod(Year, 4) && Mod(Year, 100) || !Mod(Year, 400)
}
}


MsgBox % "The year 1604 was " (IsLeapYear(1604) ? "" : "not ") "a leap year"</lang>
MsgBox % "The year 1604 was " (IsLeapYear(1604) ? "" : "not ") "a leap year"</syntaxhighlight>
{{out}}
{{out}}
<pre>The year 1600 was a leap year
<pre>The year 1600 was a leap year
Line 511: Line 511:


=={{header|AutoIt}}==
=={{header|AutoIt}}==
<lang AutoIt>; AutoIt Version: 3.3.8.1
<syntaxhighlight lang="autoit">; AutoIt Version: 3.3.8.1
$Year = 2012
$Year = 2012
$sNot = " not"
$sNot = " not"
Line 523: Line 523:


; == But it exists the standard UDF "Date.au3" with this function: "_IsLeapYear($Year)"
; == But it exists the standard UDF "Date.au3" with this function: "_IsLeapYear($Year)"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 531: Line 531:


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>function leapyear( year )
<syntaxhighlight lang="awk">function leapyear( year )
{
{
if ( year % 100 == 0 )
if ( year % 100 == 0 )
Line 537: Line 537:
else
else
return ( year % 4 == 0 )
return ( year % 4 == 0 )
}</lang>
}</syntaxhighlight>


=={{header|Bash}}==
=={{header|Bash}}==
<syntaxhighlight lang="bash">
<lang Bash>
#!/bin/bash
#!/bin/bash


Line 580: Line 580:
# Save the above to a file named is_leap_year.sh, then issue the following command to run the 5 tests of the function
# Save the above to a file named is_leap_year.sh, then issue the following command to run the 5 tests of the function
# bash is_leap_year.sh
# bash is_leap_year.sh
</syntaxhighlight>
</lang>


=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
A one-liner combination from the [[#Commodore_BASIC|Commodore BASIC]] and [[#GW_BASIC|GW-BASIC]] solutions.
A one-liner combination from the [[#Commodore_BASIC|Commodore BASIC]] and [[#GW_BASIC|GW-BASIC]] solutions.
<lang gwbasic>FOR Y = 1750 TO 2021: PRINT MID$ ( STR$ (Y) + " ",1,5 * (Y / 4 = INT (Y / 4)) * ((Y / 100 < > INT (Y / 100)) + (Y / 400 = INT (Y / 400))));: NEXT</lang>
<syntaxhighlight lang="gwbasic">FOR Y = 1750 TO 2021: PRINT MID$ ( STR$ (Y) + " ",1,5 * (Y / 4 = INT (Y / 4)) * ((Y / 100 < > INT (Y / 100)) + (Y / 400 = INT (Y / 400))));: NEXT</syntaxhighlight>
==={{header|BASIC256}}===
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<lang BASIC256># year is a BASIC-256 keyword
<syntaxhighlight lang="basic256"># year is a BASIC-256 keyword
function leapyear(year_)
function leapyear(year_)
if (year_ mod 4) <> 0 then return FALSE
if (year_ mod 4) <> 0 then return FALSE
Line 607: Line 607:
if (year_ mod 4) = 3 then print ""
if (year_ mod 4) = 3 then print ""
next year_
next year_
end</lang>
end</syntaxhighlight>




==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
<lang bbcbasic> REPEAT
<syntaxhighlight lang="bbcbasic"> REPEAT
INPUT "Enter a year: " year%
INPUT "Enter a year: " year%
IF FNleap(year%) THEN
IF FNleap(year%) THEN
Line 622: Line 622:
DEF FNleap(yr%)
DEF FNleap(yr%)
= (yr% MOD 4 = 0) AND ((yr% MOD 400 = 0) OR (yr% MOD 100 <> 0))</lang>
= (yr% MOD 4 = 0) AND ((yr% MOD 400 = 0) OR (yr% MOD 100 <> 0))</syntaxhighlight>


Much quicker without full evaluation:
Much quicker without full evaluation:


<lang bbcbasic>DEFFNleap(yr%)
<syntaxhighlight lang="bbcbasic">DEFFNleap(yr%)
IF yr% MOD 4 THEN =FALSE
IF yr% MOD 4 THEN =FALSE
IF yr% MOD 400 ELSE =TRUE
IF yr% MOD 400 ELSE =TRUE
IF yr% MOD 100 ELSE =FALSE
IF yr% MOD 100 ELSE =FALSE
=TRUE</lang>
=TRUE</syntaxhighlight>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
An old-timey solution:
An old-timey solution:
<lang BASIC>10 DEF FNLY(Y)=(Y/4=INT(Y/4))*((Y/100<>INT(Y/100))+(Y/400=INT(Y/400)))</lang>
<syntaxhighlight lang="basic">10 DEF FNLY(Y)=(Y/4=INT(Y/4))*((Y/100<>INT(Y/100))+(Y/400=INT(Y/400)))</syntaxhighlight>


Or, using Simons' BASIC's MOD function:
Or, using Simons' BASIC's MOD function:
===={{header|Simons' BASIC}}====
===={{header|Simons' BASIC}}====
<lang BASIC>10 DEF FNLY(Y)=(0=MOD(Y,4))*((0<MOD(Y,100))+(0=MOD(Y,400)))</lang>
<syntaxhighlight lang="basic">10 DEF FNLY(Y)=(0=MOD(Y,4))*((0<MOD(Y,100))+(0=MOD(Y,400)))</syntaxhighlight>


==={{header|GW-BASIC}}===
==={{header|GW-BASIC}}===
Prints all the leap years from 1750 to 2021. Note the correct behaviour of 1800, 1900, and 2000.
Prints all the leap years from 1750 to 2021. Note the correct behaviour of 1800, 1900, and 2000.
<lang gwbasic>10 FOR Y = 1750 TO 2021
<syntaxhighlight lang="gwbasic">10 FOR Y = 1750 TO 2021
20 GOSUB 1000
20 GOSUB 1000
30 IF L = 1 THEN PRINT Y;" ";
30 IF L = 1 THEN PRINT Y;" ";
Line 651: Line 651:
1020 IF Y MOD 100 = 0 AND Y MOD 400 <> 0 THEN RETURN
1020 IF Y MOD 100 = 0 AND Y MOD 400 <> 0 THEN RETURN
1030 L = 1
1030 L = 1
1040 RETURN</lang>
1040 RETURN</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
1752 1756 1760 1764 1768 1772 1776 1780 1784 1788 1792 1796 1804 1808 1812 1816 1820 1824 1828
1752 1756 1760 1764 1768 1772 1776 1780 1784 1788 1792 1796 1804 1808 1812 1816 1820 1824 1828
Line 658: Line 658:


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>100 PROGRAM "Leapyear.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "Leapyear.bas"
110 FOR I=1990 TO 2020
110 FOR I=1990 TO 2020
120 IF LEAPY(I) THEN
120 IF LEAPY(I) THEN
Line 666: Line 666:
160 END IF
160 END IF
170 NEXT
170 NEXT
180 DEF LEAPY(Y)=MOD(Y,4)=0 AND MOD(Y,100) OR MOD(Y,400)=0</lang>
180 DEF LEAPY(Y)=MOD(Y,4)=0 AND MOD(Y,100) OR MOD(Y,400)=0</syntaxhighlight>


==={{header|Sinclair ZX81 BASIC}}===
==={{header|Sinclair ZX81 BASIC}}===
ZX81 BASIC does not support user-defined functions, even the single-expression functions that are provided by many contemporary dialects; so we have to fake it using a subroutine and pass everything in global variables.
ZX81 BASIC does not support user-defined functions, even the single-expression functions that are provided by many contemporary dialects; so we have to fake it using a subroutine and pass everything in global variables.
<lang basic>5000 LET L=Y/4=INT (Y/4) AND (Y/100<>INT (Y/100) OR Y/400=INT (Y/400))
<syntaxhighlight lang="basic">5000 LET L=Y/4=INT (Y/4) AND (Y/100<>INT (Y/100) OR Y/400=INT (Y/400))
5010 RETURN</lang>
5010 RETURN</syntaxhighlight>
An example showing how to call it:
An example showing how to call it:
<lang basic>10 INPUT Y
<syntaxhighlight lang="basic">10 INPUT Y
20 GOSUB 5000
20 GOSUB 5000
30 PRINT Y;" IS ";
30 PRINT Y;" IS ";
40 IF NOT L THEN PRINT "NOT ";
40 IF NOT L THEN PRINT "NOT ";
50 PRINT "A LEAP YEAR."
50 PRINT "A LEAP YEAR."
60 STOP</lang>
60 STOP</syntaxhighlight>


==={{Header|Tiny BASIC}}===
==={{Header|Tiny BASIC}}===
<lang Tiny BASIC>REM Rosetta Code problem: https://rosettacode.org/wiki/Leap_year
<syntaxhighlight lang="tiny basic">REM Rosetta Code problem: https://rosettacode.org/wiki/Leap_year
REM by Jjuanhdez, 06/2022
REM by Jjuanhdez, 06/2022


Line 698: Line 698:
110 IF (Y - (Y / 400) * 400) <> 0 THEN GOTO 120
110 IF (Y - (Y / 400) * 400) <> 0 THEN GOTO 120
LET L = 1
LET L = 1
120 RETURN</lang>
120 RETURN</syntaxhighlight>


==={{header|ZX Spectrum Basic}}===
==={{header|ZX Spectrum Basic}}===
<lang zxbasic>10 DEF FN l(y)=y/4=INT (y/4) AND (y/100<>INT (y/100) OR y/400=INT (y/400))
<syntaxhighlight lang="zxbasic">10 DEF FN l(y)=y/4=INT (y/4) AND (y/100<>INT (y/100) OR y/400=INT (y/400))
</syntaxhighlight>
</lang>


==={{header|QBasic}}===
==={{header|QBasic}}===
Note that the <code>year%</code> function is not needed for most modern BASICs.
Note that the <code>year%</code> function is not needed for most modern BASICs.
<lang qbasic>DECLARE FUNCTION diy% (y AS INTEGER)
<syntaxhighlight lang="qbasic">DECLARE FUNCTION diy% (y AS INTEGER)
DECLARE FUNCTION isLeapYear% (yr AS INTEGER)
DECLARE FUNCTION isLeapYear% (yr AS INTEGER)
DECLARE FUNCTION year% (date AS STRING)
DECLARE FUNCTION year% (date AS STRING)
Line 730: Line 730:
FUNCTION year% (date AS STRING)
FUNCTION year% (date AS STRING)
year% = VAL(RIGHT$(date, 4))
year% = VAL(RIGHT$(date, 4))
END FUNCTION</lang>
END FUNCTION</syntaxhighlight>


==={{header|QL SuperBASIC}}===
==={{header|QL SuperBASIC}}===
<lang qbasic>
<syntaxhighlight lang="qbasic">
AUTO
AUTO
REM Is% a non-proleptic Gregorian year y$<=9999 leap (0) 0R ordinary (1)?
REM Is% a non-proleptic Gregorian year y$<=9999 leap (0) 0R ordinary (1)?
Line 743: Line 743:
END DEF Is%
END DEF Is%
ctrl+space
ctrl+space
</syntaxhighlight>
</lang>
using only power-of-2 divisions. N.B. the inverted logic brings home the BaCon code's flaw
using only power-of-2 divisions. N.B. the inverted logic brings home the BaCon code's flaw
{{output}}
{{output}}
Line 757: Line 757:
==={{header|BaCon}}===
==={{header|BaCon}}===
From the Ada shortcut calculation
From the Ada shortcut calculation
<lang qbasic>' Leap year
<syntaxhighlight lang="qbasic">' Leap year
FUNCTION leapyear(NUMBER y) TYPE NUMBER
FUNCTION leapyear(NUMBER y) TYPE NUMBER
RETURN IIF(MOD(y, 4) = 0, IIF(MOD(y, 16) = 0, IIF(MOD(y, 100) != 0, TRUE, FALSE), TRUE), FALSE)
RETURN IIF(MOD(y, 4) = 0, IIF(MOD(y, 16) = 0, IIF(MOD(y, 100) != 0, TRUE, FALSE), TRUE), FALSE)
Line 768: Line 768:
WEND
WEND


DATA 1600, 1700, 1800, 1900, 1901, 1996, 2000, 2001, 2004, 0</lang>
DATA 1600, 1700, 1800, 1900, 1901, 1996, 2000, 2001, 2004, 0</syntaxhighlight>


{{out}}
{{out}}
Line 783: Line 783:


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off


::The Main Thing...
::The Main Thing...
Line 811: Line 811:
echo %year% is NOT a leap year.
echo %year% is NOT a leap year.
goto :EOF
goto :EOF
::/The Function...</lang>
::/The Function...</syntaxhighlight>
{{out}}
{{out}}
<pre>1900 is NOT a leap year.
<pre>1900 is NOT a leap year.
Line 831: Line 831:


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


let leap(year) = year rem 400 = 0 | (year rem 4 = 0 & year rem 100 ~= 0)
let leap(year) = year rem 400 = 0 | (year rem 4 = 0 & year rem 100 ~= 0)
Line 841: Line 841:
writef("%N %S a leap year.*N",
writef("%N %S a leap year.*N",
years!i, leap(years!i) -> "is", "is not")
years!i, leap(years!i) -> "is", "is not")
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>1899 is not a leap year.
<pre>1899 is not a leap year.
Line 862: Line 862:
{{trans|C}}
{{trans|C}}


<lang befunge>0"2("*:3-:1-:2-:"^"-v<
<syntaxhighlight lang="befunge">0"2("*:3-:1-:2-:"^"-v<
v*%"d"\!%4::,,"is".:<|
v*%"d"\!%4::,,"is".:<|
>\45*:*%!+#v_ "ton"vv<
>\45*:*%!+#v_ "ton"vv<
v"ear."+550<,,,,*84<$#
v"ear."+550<,,,,*84<$#
>"y pael a ">:#,_$:#@^</lang>
>"y pael a ">:#,_$:#@^</syntaxhighlight>


{{out}}
{{out}}
Line 876: Line 876:


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat> ( leap-year
<syntaxhighlight lang="bracmat"> ( leap-year
=
=
. mod$(!arg.100):0
. mod$(!arg.100):0
Line 890: Line 890:
)
)
)
)
& ;</lang>
& ;</syntaxhighlight>
{{out}}
{{out}}
<pre>1600 is a leap year
<pre>1600 is a leap year
Line 901: Line 901:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int is_leap_year(int year)
int is_leap_year(int year)
Line 915: Line 915:
printf("%d is %sa leap year.\n", year, (is_leap_year(year) == 1 ? "" : "not "));
printf("%d is %sa leap year.\n", year, (is_leap_year(year) == 1 ? "" : "not "));
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 926: Line 926:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program
class Program
Line 939: Line 939:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1900 is not a leap year.
<pre>1900 is not a leap year.
Line 949: Line 949:
Uses C++11. Compile with
Uses C++11. Compile with
g++ -std=c++11 leap_year.cpp
g++ -std=c++11 leap_year.cpp
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


bool is_leap_year(int year) {
bool is_leap_year(int year) {
Line 959: Line 959:
std::cout << year << (is_leap_year(year) ? " is" : " is not") << " a leap year.\n";
std::cout << year << (is_leap_year(year) ? " is" : " is not") << " a leap year.\n";
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 970: Line 970:


=={{header|Clipper}}==
=={{header|Clipper}}==
<lang Clipper>Function IsLeapYear( nYear )
<syntaxhighlight lang="clipper">Function IsLeapYear( nYear )
Return Iif( nYear%100 == 0, (nYear%400 == 0), (nYear%4 == 0) )</lang>
Return Iif( nYear%100 == 0, (nYear%400 == 0), (nYear%4 == 0) )</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(defn leap-year? [y]
<syntaxhighlight lang="clojure">(defn leap-year? [y]
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400)))))</lang>
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400)))))</syntaxhighlight>


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>is_leap_year = proc (year: int) returns (bool)
<syntaxhighlight lang="clu">is_leap_year = proc (year: int) returns (bool)
return(year//400 =0 cor (year//4 = 0 cand year//100 ~= 0))
return(year//400 =0 cor (year//4 = 0 cand year//100 ~= 0))
end is_leap_year
end is_leap_year
Line 993: Line 993:
stream$putl(po, "a leap year.")
stream$putl(po, "a leap year.")
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>1899 is not a leap year.
<pre>1899 is not a leap year.
Line 1,012: Line 1,012:


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. leap-year.
PROGRAM-ID. leap-year.


Line 1,040: Line 1,040:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


Using Date Intrinsic Functions
Using Date Intrinsic Functions
<syntaxhighlight lang="cobol">
<lang COBOL>
program-id. leap-yr.
program-id. leap-yr.
*> Given a year, where 1601 <= year <= 9999
*> Given a year, where 1601 <= year <= 9999
Line 1,077: Line 1,077:
.
.
end program leap-yr.
end program leap-yr.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,095: Line 1,095:


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>(defun leap-year-p (year)
<syntaxhighlight lang="lisp">(defun leap-year-p (year)
(destructuring-bind (fh h f)
(destructuring-bind (fh h f)
(mapcar #'(lambda (n) (zerop (mod year n))) '(400 100 4))
(mapcar #'(lambda (n) (zerop (mod year n))) '(400 100 4))
(or fh (and (not h) f))))</lang>
(or fh (and (not h) f))))</syntaxhighlight>


=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
BlackBox Component Builder
BlackBox Component Builder
<lang oberon2>
<syntaxhighlight lang="oberon2">
MODULE LeapYear;
MODULE LeapYear;
IMPORT StdLog, Strings, Args;
IMPORT StdLog, Strings, Args;
Line 1,132: Line 1,132:
END Do;
END Do;
END LeapYear.
END LeapYear.
</syntaxhighlight>
</lang>
Execute: ^Q LeapYear.Do 2000 2004 2013~<br/>
Execute: ^Q LeapYear.Do 2000 2004 2013~<br/>
{{out}}
{{out}}
Line 1,143: Line 1,143:
=={{header|Crystal}}==
=={{header|Crystal}}==


<lang ruby>p Time.leap_year?(2020)
<syntaxhighlight lang="ruby">p Time.leap_year?(2020)
p Time.leap_year?(2021)
p Time.leap_year?(2021)
p Time.leap_year?(2022)</lang>
p Time.leap_year?(2022)</syntaxhighlight>


<pre>
<pre>
Line 1,154: Line 1,154:


=={{header|D}}==
=={{header|D}}==
<lang d>import std.algorithm;
<syntaxhighlight lang="d">import std.algorithm;


bool leapYear(in uint y) pure nothrow {
bool leapYear(in uint y) pure nothrow {
Line 1,166: Line 1,166:
1973, 2100, 2107, 2200, 2203, 2289];
1973, 2100, 2107, 2200, 2203, 2289];
assert(filter!leapYear(bad ~ good).equal(good));
assert(filter!leapYear(bad ~ good).equal(good));
}</lang>
}</syntaxhighlight>




Using the datetime library:
Using the datetime library:
<lang d>import std.datetime;
<syntaxhighlight lang="d">import std.datetime;


void main() {
void main() {
Line 1,178: Line 1,178:
assert(DateTime(2000, 1, 1).isLeapYear);
assert(DateTime(2000, 1, 1).isLeapYear);
}
}
</syntaxhighlight>
</lang>


=={{header|Dart}}==
=={{header|Dart}}==


<lang Dart>class Leap {
<syntaxhighlight lang="dart">class Leap {
bool leapYear(num year) {
bool leapYear(num year) {
return (year % 400 == 0) || (( year % 100 != 0) && (year % 4 == 0));
return (year % 400 == 0) || (( year % 100 != 0) && (year % 4 == 0));
Line 1,190: Line 1,190:
// Source: https://api.flutter.dev/flutter/quiver.time/isLeapYear.html
// Source: https://api.flutter.dev/flutter/quiver.time/isLeapYear.html
}
}
}</lang>
}</syntaxhighlight>


=={{header|Dc}}==
=={{header|Dc}}==
Directly taken from Wikipedia.
Directly taken from Wikipedia.
{{works with|GNU dc}}
{{works with|GNU dc}}
<lang Dc>[0q]s0
<syntaxhighlight lang="dc">[0q]s0
[1q]s1
[1q]s1


Line 1,218: Line 1,218:
1989 lTx
1989 lTx
1900 lTx
1900 lTx
2000 lTx</lang>
2000 lTx</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,229: Line 1,229:
=={{header|Delphi}}/{{header|Pascal}}==
=={{header|Delphi}}/{{header|Pascal}}==
Delphi has standard function IsLeapYear in SysUtils unit.
Delphi has standard function IsLeapYear in SysUtils unit.
<lang Delphi>program TestLeapYear;
<syntaxhighlight lang="delphi">program TestLeapYear;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 1,247: Line 1,247:
Writeln(Year, ' is not a Leap year');
Writeln(Year, ' is not a Leap year');
Readln;
Readln;
end.</lang>
end.</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec leap_year(word year) bool:
<syntaxhighlight lang="draco">proc nonrec leap_year(word year) bool:
year%400=0 or (year%4=0 and year%100/=0)
year%400=0 or (year%4=0 and year%100/=0)
corp
corp
Line 1,264: Line 1,264:
"a leap year.")
"a leap year.")
od
od
corp</lang>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre>1899 is not a leap year.
<pre>1899 is not a leap year.
Line 1,283: Line 1,283:


=={{header|DWScript}}==
=={{header|DWScript}}==
<lang Delphi>function IsLeapYear(y : Integer) : Boolean;
<syntaxhighlight lang="delphi">function IsLeapYear(y : Integer) : Boolean;
begin
begin
Result:= (y mod 4 = 0)
Result:= (y mod 4 = 0)
Line 1,303: Line 1,303:
PrintLn('Checking non-leap years');
PrintLn('Checking non-leap years');
for i in bad do
for i in bad do
if IsLeapYear(i) then PrintLn(i);</lang>
if IsLeapYear(i) then PrintLn(i);</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang Dyalect>func isLeap(y) {
<syntaxhighlight lang="dyalect">func isLeap(y) {
if y % 100 == 0 {
if y % 100 == 0 {
y % 400 == 0
y % 400 == 0
Line 1,315: Line 1,315:
}
}


print(isLeap(1984))</lang>
print(isLeap(1984))</syntaxhighlight>


{{out}}
{{out}}
Line 1,322: Line 1,322:


=={{header|Ela}}==
=={{header|Ela}}==
<lang ela>isLeap y | y % 100 == 0 = y % 400 == 0
<syntaxhighlight lang="ela">isLeap y | y % 100 == 0 = y % 400 == 0
| else = y % 4 == 0</lang>
| else = y % 4 == 0</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>leap_year? = fn(year) -> :calendar.is_leap_year(year) end
<syntaxhighlight lang="elixir">leap_year? = fn(year) -> :calendar.is_leap_year(year) end
IO.inspect for y <- 2000..2020, leap_year?.(y), do: y</lang>
IO.inspect for y <- 2000..2020, leap_year?.(y), do: y</syntaxhighlight>


{{out}}
{{out}}
Line 1,336: Line 1,336:
=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
{{trans|Scheme}}
{{trans|Scheme}}
<lang lisp>(defun leap-year-p (year)
<syntaxhighlight lang="lisp">(defun leap-year-p (year)
(apply (lambda (a b c) (or a (and (not b) c)))
(apply (lambda (a b c) (or a (and (not b) c)))
(mapcar (lambda (n) (zerop (mod year n)))
(mapcar (lambda (n) (zerop (mod year n)))
'(400 100 4))))</lang>
'(400 100 4))))</syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>
<syntaxhighlight lang="erlang">
-module(gregorian).
-module(gregorian).
-export([leap/1]).
-export([leap/1]).


leap( Year ) -> calendar:is_leap_year( Year ).
leap( Year ) -> calendar:is_leap_year( Year ).
</syntaxhighlight>
</lang>


=={{header|ERRE}}==
=={{header|ERRE}}==
<lang ERRE>PROGRAM LEAP_YEAR
<syntaxhighlight lang="erre">PROGRAM LEAP_YEAR


FUNCTION LEAP(YR%)
FUNCTION LEAP(YR%)
Line 1,366: Line 1,366:
END IF
END IF
END LOOP
END LOOP
END PROGRAM</lang>
END PROGRAM</syntaxhighlight>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang euphoria>function isLeapYear(integer year)
<syntaxhighlight lang="euphoria">function isLeapYear(integer year)
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
end function</lang>
end function</syntaxhighlight>


=={{header|Excel}}==
=={{header|Excel}}==
Take two cells, say A1 and B1, in B1 type in :
Take two cells, say A1 and B1, in B1 type in :


<syntaxhighlight lang="excel">
<lang Excel>
=IF(OR(NOT(MOD(A1,400)),AND(NOT(MOD(A1,4)),MOD(A1,100))),"Leap Year","Not a Leap Year")
=IF(OR(NOT(MOD(A1,400)),AND(NOT(MOD(A1,4)),MOD(A1,100))),"Leap Year","Not a Leap Year")
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,398: Line 1,398:


{{Works with|Office 365 betas 2021}}
{{Works with|Office 365 betas 2021}}
<lang lisp>ISLEAPYEAR
<syntaxhighlight lang="lisp">ISLEAPYEAR
=LAMBDA(y,
=LAMBDA(y,
OR(
OR(
Line 1,407: Line 1,407:
)
)
)
)
)</lang>
)</syntaxhighlight>


{{Out}}
{{Out}}
Line 1,445: Line 1,445:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>let isLeapYear = System.DateTime.IsLeapYear
<syntaxhighlight lang="fsharp">let isLeapYear = System.DateTime.IsLeapYear
assert isLeapYear 1996
assert isLeapYear 1996
assert isLeapYear 2000
assert isLeapYear 2000
assert not (isLeapYear 2001)
assert not (isLeapYear 2001)
assert not (isLeapYear 1900)</lang>
assert not (isLeapYear 1900)</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
Call ''leap-year?'' word from ''calendars'' vocabulary. For example:
Call ''leap-year?'' word from ''calendars'' vocabulary. For example:
<lang factor>USING: calendar prettyprint ;
<syntaxhighlight lang="factor">USING: calendar prettyprint ;
2011 leap-year? .</lang>
2011 leap-year? .</syntaxhighlight>
Factor uses proleptic Gregorian calendar.
Factor uses proleptic Gregorian calendar.


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang>Function IsLeap(y) = if y|4>0 then 0 else if y|100=0 and y|400>0 then 0 else 1 fi fi.</lang>
<syntaxhighlight lang="text">Function IsLeap(y) = if y|4>0 then 0 else if y|100=0 and y|400>0 then 0 else 1 fi fi.</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
<lang forth>: leap-year? ( y -- ? )
<syntaxhighlight lang="forth">: leap-year? ( y -- ? )
dup 400 mod 0= if drop true exit then
dup 400 mod 0= if drop true exit then
dup 100 mod 0= if drop false exit then
dup 100 mod 0= if drop false exit then
4 mod 0= ;</lang>
4 mod 0= ;</syntaxhighlight>


Or more simply (but always computing three "mod"):
Or more simply (but always computing three "mod"):
<lang forth>: leap-year? dup 4 mod 0= over 16 mod 0= rot 25 mod 0= not or and ;</lang>
<syntaxhighlight lang="forth">: leap-year? dup 4 mod 0= over 16 mod 0= rot 25 mod 0= not or and ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
<lang fortran>program leap
<syntaxhighlight lang="fortran">program leap
implicit none
implicit none


Line 1,486: Line 1,486:
end function leap_year
end function leap_year
end program leap</lang>
end program leap</syntaxhighlight>
{{out}}
{{out}}
<pre> F T F T </pre>
<pre> F T F T </pre>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang FreeBASIC>' version 23-06-2015
<syntaxhighlight lang="freebasic">' version 23-06-2015
' compile with: fbc -s console
' compile with: fbc -s console


Line 1,532: Line 1,532:
Print : Print "hit any key to end program"
Print : Print "hit any key to end program"
Sleep
Sleep
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre> 1800 is not a leap year
<pre> 1800 is not a leap year
Line 1,554: Line 1,554:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>window 1
<syntaxhighlight lang="futurebasic">window 1


// In-line C function to generate random number in range
// In-line C function to generate random number in range
Line 1,605: Line 1,605:
next
next


HandleEvents</lang>
HandleEvents</syntaxhighlight>


Output (results will vary for random years):
Output (results will vary for random years):
Line 1,654: Line 1,654:


=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
<syntaxhighlight lang="gambas">Public Sub Form_Open()
Dim dDate As Date
Dim dDate As Date
Dim siYear As Short = InputBox("Enter a year", "Leap year test")
Dim siYear As Short = InputBox("Enter a year", "Leap year test")
Line 1,664: Line 1,664:
Message(siYear & sMessage)
Message(siYear & sMessage)


End</lang>
End</syntaxhighlight>


Output:
Output:
Line 1,672: Line 1,672:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>IsLeapYear := function(n)
<syntaxhighlight lang="gap">IsLeapYear := function(n)
return (n mod 4 = 0) and ((n mod 100 <> 0) or (n mod 400 = 0));
return (n mod 4 = 0) and ((n mod 100 <> 0) or (n mod 400 = 0));
end;
end;
Line 1,679: Line 1,679:
IsLeapYear := function(n)
IsLeapYear := function(n)
return DaysInYear(n) = 366;
return DaysInYear(n) = 366;
end;</lang>
end;</syntaxhighlight>


=={{header|Genie}}==
=={{header|Genie}}==
Dialect conversion from Vala entry.
Dialect conversion from Vala entry.


<lang genie>[indent=4]
<syntaxhighlight lang="genie">[indent=4]
/*
/*
Leap year, in Genie
Leap year, in Genie
Line 1,696: Line 1,696:
for year in years
for year in years
status:string = year.is_leap_year() ? "" : "not "
status:string = year.is_leap_year() ? "" : "not "
stdout.printf("%d is %sa leap year.\n", year, status)</lang>
stdout.printf("%d is %sa leap year.\n", year, status)</syntaxhighlight>


{{out}}
{{out}}
Line 1,709: Line 1,709:


=={{header|Go}}==
=={{header|Go}}==
<lang go>func isLeap(year int) bool {
<syntaxhighlight lang="go">func isLeap(year int) bool {
return year%400 == 0 || year%4 == 0 && year%100 != 0
return year%400 == 0 || year%4 == 0 && year%100 != 0
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
Solution:
Solution:
<lang groovy>(1900..2012).findAll {new GregorianCalendar().isLeapYear(it)}.each {println it}</lang>
<syntaxhighlight lang="groovy">(1900..2012).findAll {new GregorianCalendar().isLeapYear(it)}.each {println it}</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:30ex;overflow:scroll;">1904
<pre style="height:30ex;overflow:scroll;">1904
Line 1,748: Line 1,748:
=={{header|GW-BASIC}}==
=={{header|GW-BASIC}}==
{{works with|PC-BASIC|any}}
{{works with|PC-BASIC|any}}
<lang qbasic>
<syntaxhighlight lang="qbasic">
10 ' Leap year
10 ' Leap year
20 DEF FN ISLEAPYEAR(Y%) = ((Y% MOD 4 = 0) AND (Y% MOD 100 <> 0)) OR (Y% MOD 400 = 0)
20 DEF FN ISLEAPYEAR(Y%) = ((Y% MOD 4 = 0) AND (Y% MOD 100 <> 0)) OR (Y% MOD 400 = 0)
Line 1,760: Line 1,760:
160 END
160 END
200 DATA 1900, 1994, 1996, 1997, 2000
200 DATA 1900, 1994, 1996, 1997, 2000
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,771: Line 1,771:


=={{header|Harbour}}==
=={{header|Harbour}}==
<lang visualfoxpro>FUNCTION IsLeapYear( nYear )
<syntaxhighlight lang="visualfoxpro">FUNCTION IsLeapYear( nYear )
RETURN iif( nYear % 100 == 0, nYear % 400 == 0, nYear % 4 == 0 )</lang>
RETURN iif( nYear % 100 == 0, nYear % 400 == 0, nYear % 4 == 0 )</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
'''Simple version'''
'''Simple version'''
<lang haskell>import Data.List
<syntaxhighlight lang="haskell">import Data.List
import Control.Monad
import Control.Monad
import Control.Arrow
import Control.Arrow
Line 1,784: Line 1,784:


isleapsf j | 0==j`mod`100 = 0 == j`mod`400
isleapsf j | 0==j`mod`100 = 0 == j`mod`400
| otherwise = 0 == j`mod`4</lang>
| otherwise = 0 == j`mod`4</syntaxhighlight>
'''Algorithmic'''
'''Algorithmic'''
<lang haskell>isleap = foldl1 ((&&).not).flip map [400, 100, 4]. ((0==).).mod</lang>
<syntaxhighlight lang="haskell">isleap = foldl1 ((&&).not).flip map [400, 100, 4]. ((0==).).mod</syntaxhighlight>
Example using isleap
Example using isleap
<lang haskell>*Main> mapM_ (putStrLn. (ap leaptext isleap)) [1900,1994,1996,1997,2000]
<syntaxhighlight lang="haskell">*Main> mapM_ (putStrLn. (ap leaptext isleap)) [1900,1994,1996,1997,2000]
1900 is not a leap year
1900 is not a leap year
1994 is not a leap year
1994 is not a leap year
1996 is a leap year
1996 is a leap year
1997 is not a leap year
1997 is not a leap year
2000 is a leap year</lang>
2000 is a leap year</syntaxhighlight>


'''TDD version'''
'''TDD version'''
<lang haskell>import Test.HUnit
<syntaxhighlight lang="haskell">import Test.HUnit


isLeapYear::Int->Bool
isLeapYear::Int->Bool
Line 1,809: Line 1,809:
,TestCase $ assertEqual "64 is a leap year" True $ isLeapYear 64
,TestCase $ assertEqual "64 is a leap year" True $ isLeapYear 64
,TestCase $ assertEqual "2000 is a leap year" True $ isLeapYear 2000
,TestCase $ assertEqual "2000 is a leap year" True $ isLeapYear 2000
,TestCase $ assertEqual "1900 is not a leap year" False $ isLeapYear 1900]</lang>
,TestCase $ assertEqual "1900 is not a leap year" False $ isLeapYear 1900]</syntaxhighlight>


=={{header|Hy}}==
=={{header|Hy}}==
<lang clojure>(defn leap? [y]
<syntaxhighlight lang="clojure">(defn leap? [y]
(and
(and
(= (% y 4) 0)
(= (% y 4) 0)
(or
(or
(!= (% y 100) 0)
(!= (% y 100) 0)
(= (% y 400) 0))))</lang>
(= (% y 400) 0))))</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Gives leap year status for 2000,1900,2012 and any arguments you give
Gives leap year status for 2000,1900,2012 and any arguments you give
<lang Icon>procedure main(arglist)
<syntaxhighlight lang="icon">procedure main(arglist)
every y := !([2000,1900,2012]|||arglist) do
every y := !([2000,1900,2012]|||arglist) do
write("The year ",y," is ", leapyear(y) | "not ","a leap year.")
write("The year ",y," is ", leapyear(y) | "not ","a leap year.")
Line 1,828: Line 1,828:
procedure leapyear(year) #: determine if year is leap
procedure leapyear(year) #: determine if year is leap
if (numeric(year) % 4 = 0 & year % 100 ~= 0) | (numeric(year) % 400 = 0) then return
if (numeric(year) % 4 = 0 & year % 100 ~= 0) | (numeric(year) % 400 = 0) then return
end</lang>
end</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
<lang j>isLeap=: 0 -/@:= 4 100 400 |/ ]</lang>
<syntaxhighlight lang="j">isLeap=: 0 -/@:= 4 100 400 |/ ]</syntaxhighlight>
Example use:
Example use:
<lang j> isLeap 1900 1996 1997 2000
<syntaxhighlight lang="j"> isLeap 1900 1996 1997 2000
0 1 0 1</lang>
0 1 0 1</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
Line 1,842: Line 1,842:
Both values are printed in the output.
Both values are printed in the output.


<lang java>import java.util.GregorianCalendar;
<syntaxhighlight lang="java">import java.util.GregorianCalendar;
import java.text.MessageFormat;
import java.text.MessageFormat;


Line 1,860: Line 1,860:
}
}


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>The year 1800 is leaper: false / false.
<pre>The year 1800 is leaper: false / false.
Line 1,874: Line 1,874:
{{works with|Java|8}}
{{works with|Java|8}}


<lang java>import java.time.Year;
<syntaxhighlight lang="java">import java.time.Year;


public class IsLeap {
public class IsLeap {
Line 1,882: Line 1,882:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>var isLeapYear = function (year) { return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); };</lang>
<syntaxhighlight lang="javascript">var isLeapYear = function (year) { return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); };</syntaxhighlight>
Or, by setting the day to the 29th and checking if the day remains
Or, by setting the day to the 29th and checking if the day remains
<lang javascript>// Month values start at 0, so 1 is for February
<syntaxhighlight lang="javascript">// Month values start at 0, so 1 is for February
var isLeapYear = function (year) { return new Date(year, 1, 29).getDate() === 29; };</lang>
var isLeapYear = function (year) { return new Date(year, 1, 29).getDate() === 29; };</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
{{trans|Julia}}
{{trans|Julia}}
<lang jq>def leap:
<syntaxhighlight lang="jq">def leap:
. as $y | ($y%4) == 0 and ($y < 1582 or ($y%400) == 0 or ($y%100) != 0);</lang>
. as $y | ($y%4) == 0 and ($y < 1582 or ($y%400) == 0 or ($y%100) != 0);</syntaxhighlight>
'''Examples''':
'''Examples''':
<lang jq>def assert(value; f):
<syntaxhighlight lang="jq">def assert(value; f):
value as $value
value as $value
| ($value|f) | if . then empty else error("assertion violation: \($value) => \(.)") end;
| ($value|f) | if . then empty else error("assertion violation: \($value) => \(.)") end;
Line 1,902: Line 1,902:


((2100, 2014, 1900, 1800, 1700, 1499) | assert(.; leap|not))
((2100, 2014, 1900, 1800, 1700, 1499) | assert(.; leap|not))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
$ jq -n -f Leap_year.jq
$ jq -n -f Leap_year.jq
Line 1,909: Line 1,909:
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>isleap(yr::Integer) = yr % 4 == 0 && (yr < 1582 || yr % 400 == 0 || yr % 100 != 0)
<syntaxhighlight lang="julia">isleap(yr::Integer) = yr % 4 == 0 && (yr < 1582 || yr % 400 == 0 || yr % 100 != 0)


@assert all(isleap, [2400, 2012, 2000, 1600, 1500, 1400])
@assert all(isleap, [2400, 2012, 2000, 1600, 1500, 1400])
@assert !any(isleap, [2100, 2014, 1900, 1800, 1700, 1499])</lang>
@assert !any(isleap, [2100, 2014, 1900, 1800, 1700, 1499])</syntaxhighlight>


=={{header|K}}==
=={{header|K}}==
<lang K> leapyear:{(+/~x!'4 100 400)!2}
<syntaxhighlight lang="k"> leapyear:{(+/~x!'4 100 400)!2}


a@&leapyear'a:1900,1994,1996,1997,2000
a@&leapyear'a:1900,1994,1996,1997,2000
1996 2000</lang>
1996 2000</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang kotlin>fun isLeapYear(year: Int) = year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)</lang>
<syntaxhighlight lang="kotlin">fun isLeapYear(year: Int) = year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>define isLeapYear(y::integer) => {
<syntaxhighlight lang="lasso">define isLeapYear(y::integer) => {
#y % 400 == 0 ? return true
#y % 400 == 0 ? return true
#y % 100 == 0 ? return false
#y % 100 == 0 ? return false
Line 1,934: Line 1,934:
isLeapYear(#test)
isLeapYear(#test)
'\r'
'\r'
^}</lang>
^}</syntaxhighlight>


{{out}}
{{out}}
Line 1,946: Line 1,946:
=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
=== Simple method ===
=== Simple method ===
<lang lb>if leap(1996)then
<syntaxhighlight lang="lb">if leap(1996)then
print "leap"
print "leap"
else
else
Line 1,955: Line 1,955:
function leap(n)
function leap(n)
leap=date$("2/29/";n)
leap=date$("2/29/";n)
end function</lang>
end function</syntaxhighlight>


=== Calculated method ===
=== Calculated method ===
<lang lb> year = 1908
<syntaxhighlight lang="lb"> year = 1908
select case
select case
case year mod 400 = 0
case year mod 400 = 0
Line 1,971: Line 1,971:
else
else
print year;" is not a leap year."
print year;" is not a leap year."
end if</lang>
end if</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
<lang lingo>on isLeapYear (year)
<syntaxhighlight lang="lingo">on isLeapYear (year)
return date(year, 2, 29).month=2
return date(year, 2, 29).month=2
end</lang>
end</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>function isLeapYear year
<syntaxhighlight lang="livecode">function isLeapYear year
return (year MOD 4 is 0) AND ((year MOD 400 is 0) OR (year MOD 100 is not 0))
return (year MOD 4 is 0) AND ((year MOD 400 is 0) OR (year MOD 100 is not 0))
end isLeapYear
end isLeapYear
Line 1,996: Line 1,996:
1996 is true
1996 is true
1997 is false
1997 is false
2000 is true </lang>
2000 is true </syntaxhighlight>


=={{header|LLVM}}==
=={{header|LLVM}}==
<lang llvm>; This is not strictly LLVM, as it uses the C library function "printf".
<syntaxhighlight lang="llvm">; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
; to just load the string into memory, and that would be boring.
Line 2,092: Line 2,092:


attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }</lang>
attributes #1 = { argmemonly nounwind }</syntaxhighlight>
{{out}}
{{out}}
<pre>1900 is not a leap year.
<pre>1900 is not a leap year.
Line 2,101: Line 2,101:


=={{header|Logo}}==
=={{header|Logo}}==
<lang logo>to multiple? :n :d
<syntaxhighlight lang="logo">to multiple? :n :d
output equal? 0 modulo :n :d
output equal? 0 modulo :n :d
end
end
to leapyear? :y
to leapyear? :y
output ifelse multiple? :y 100 [multiple? :y 400] [multiple? :y 4]
output ifelse multiple? :y 100 [multiple? :y 400] [multiple? :y 4]
end</lang>
end</syntaxhighlight>


=={{header|Logtalk}}==
=={{header|Logtalk}}==
<lang logtalk>leap_year(Year) :-
<syntaxhighlight lang="logtalk">leap_year(Year) :-
( mod(Year, 4) =:= 0, mod(Year, 100) =\= 0 ->
( mod(Year, 4) =:= 0, mod(Year, 100) =\= 0 ->
true
true
; mod(Year, 400) =:= 0
; mod(Year, 400) =:= 0
).</lang>
).</syntaxhighlight>


=={{header|LOLCODE}}==
=={{header|LOLCODE}}==
<lang lolcode>BTW Determine if a Gregorian calendar year is leap
<syntaxhighlight lang="lolcode">BTW Determine if a Gregorian calendar year is leap
HAI 1.3
HAI 1.3
HOW IZ I Leap YR Year
HOW IZ I Leap YR Year
Line 2,162: Line 2,162:


KTHXBYE
KTHXBYE
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>1900 is NOT a leap year
<pre>1900 is NOT a leap year
Line 2,173: Line 2,173:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>function isLeapYear(year)
<syntaxhighlight lang="lua">function isLeapYear(year)
return year%4==0 and (year%100~=0 or year%400==0)
return year%4==0 and (year%100~=0 or year%400==0)
end</lang>
end</syntaxhighlight>


=={{header|Maple}}==
=={{header|Maple}}==
<lang maple>isLeapYear := proc(year)
<syntaxhighlight lang="maple">isLeapYear := proc(year)
if not year mod 4 = 0 or (year mod 100 = 0 and not year mod 400 = 0) then
if not year mod 4 = 0 or (year mod 100 = 0 and not year mod 400 = 0) then
return false;
return false;
Line 2,184: Line 2,184:
return true;
return true;
end if;
end if;
end proc:</lang>
end proc:</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Dates are handled by built-in functions in the Wolfram Language
Dates are handled by built-in functions in the Wolfram Language
<lang Mathematica>LeapYearQ[2002]</lang>
<syntaxhighlight lang="mathematica">LeapYearQ[2002]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
MATLAB, conveniently, provides a function that returns the last day of an arbitrary month of the calendar given the year. Using the fact that February is 29 days long during a leap year, we can write a one-liner that solves this task.
MATLAB, conveniently, provides a function that returns the last day of an arbitrary month of the calendar given the year. Using the fact that February is 29 days long during a leap year, we can write a one-liner that solves this task.
<lang MATLAB>function TrueFalse = isLeapYear(year)
<syntaxhighlight lang="matlab">function TrueFalse = isLeapYear(year)
TrueFalse = (eomday(year,2) == 29);
TrueFalse = (eomday(year,2) == 29);
end</lang>
end</syntaxhighlight>


===Using Logical and modular functions===
===Using Logical and modular functions===
<lang matlab>x = ~mod(YEAR, 4) & (mod(YEAR, 100) | ~mod(YEAR, 400))</lang>
<syntaxhighlight lang="matlab">x = ~mod(YEAR, 4) & (mod(YEAR, 100) | ~mod(YEAR, 400))</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>leapyearp(year) := is(mod(year, 4) = 0 and
<syntaxhighlight lang="maxima">leapyearp(year) := is(mod(year, 4) = 0 and
(mod(year, 100) # 0 or mod(year, 400) = 0))$</lang>
(mod(year, 100) # 0 or mod(year, 400) = 0))$</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang mercury>:- pred is_leap_year(int::in) is semidet.
<syntaxhighlight lang="mercury">:- pred is_leap_year(int::in) is semidet.


is_leap_year(Year) :-
is_leap_year(Year) :-
( if Year mod 100 = 0 then Year mod 400 = 0 else Year mod 4 = 0 ).</lang>
( if Year mod 100 = 0 then Year mod 400 = 0 else Year mod 4 = 0 ).</syntaxhighlight>


Usage:
Usage:


<lang mercury>:- module leap_year.
<syntaxhighlight lang="mercury">:- module leap_year.
:- interface.
:- interface.


Line 2,228: Line 2,228:
write_year_kind(Year, !IO) :-
write_year_kind(Year, !IO) :-
io.format("%d %s a leap year.\n",
io.format("%d %s a leap year.\n",
[i(Year), s(if is_leap_year(Year) then "is" else "is not" )], !IO).</lang>
[i(Year), s(if is_leap_year(Year) then "is" else "is not" )], !IO).</syntaxhighlight>


=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.6}}
{{works with|min|0.19.6}}
<lang min>(mod 0 ==) :divisor?
<syntaxhighlight lang="min">(mod 0 ==) :divisor?
(((400 divisor?) (4 divisor?) (100 divisor? not)) cleave and or) :leap-year?</lang>
(((400 divisor?) (4 divisor?) (100 divisor? not)) cleave and or) :leap-year?</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>isLeapYear = function(year)
<syntaxhighlight lang="miniscript">isLeapYear = function(year)
return year%4==0 and (year % 100 or not year % 400)
return year%4==0 and (year % 100 or not year % 400)
end function</lang>
end function</syntaxhighlight>


=={{header|MIPS Assembly}}==
=={{header|MIPS Assembly}}==
Pass year in a0, returns boolean in v0.
Pass year in a0, returns boolean in v0.
<lang mips>
<syntaxhighlight lang="mips">
IsLeap: andi $a1, $a0, 3 #a0 is year to test
IsLeap: andi $a1, $a0, 3 #a0 is year to test
bnez $a1 NotLeap
bnez $a1 NotLeap
Line 2,256: Line 2,256:
NotLeap:li $v0, 0
NotLeap:li $v0, 0
jr $ra
jr $ra
</syntaxhighlight>
</lang>


=={{header|МК-61/52}}==
=={{header|МК-61/52}}==
<lang>П0 1 0 0 / {x} x=0 14 ИП0 4
<syntaxhighlight lang="text">П0 1 0 0 / {x} x=0 14 ИП0 4
0 0 ПП 18 ИП0 4 ПП 18 / {x}
0 0 ПП 18 ИП0 4 ПП 18 / {x}
x=0 24 1 С/П 0 С/П</lang>
x=0 24 1 С/П 0 С/П</syntaxhighlight>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE LeapYear;
<syntaxhighlight lang="modula2">MODULE LeapYear;
FROM FormatString IMPORT FormatString;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
FROM Terminal IMPORT WriteString,ReadChar;
Line 2,293: Line 2,293:
Print(2000);
Print(2000);
ReadChar
ReadChar
END LeapYear.</lang>
END LeapYear.</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<lang MUMPS>ILY(X) ;IS IT A LEAP YEAR?
<syntaxhighlight lang="mumps">ILY(X) ;IS IT A LEAP YEAR?
QUIT ((X#4=0)&(X#100'=0))!((X#100=0)&(X#400=0))</lang>
QUIT ((X#4=0)&(X#100'=0))!((X#100=0)&(X#400=0))</syntaxhighlight>
Usage: <pre>USER>W $SELECT($$ILY^ROSETTA(1900):"Yes",1:"No")
Usage: <pre>USER>W $SELECT($$ILY^ROSETTA(1900):"Yes",1:"No")
No
No
Line 2,307: Line 2,307:
=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
{{trans|Python}}
{{trans|Python}}
<lang Nanoquery>def isLeapYear(year)
<syntaxhighlight lang="nanoquery">def isLeapYear(year)
if (year % 100 = 0)
if (year % 100 = 0)
return (year % 400 = 0)
return (year % 400 = 0)
Line 2,313: Line 2,313:
return (year % 4 = 0)
return (year % 4 = 0)
end
end
end</lang>
end</syntaxhighlight>


=={{header|Neko}}==
=={{header|Neko}}==
Translating from C
Translating from C


<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
<doc><h2>Leap year, in Neko</h2></doc>
<doc><h2>Leap year, in Neko</h2></doc>
**/
**/
Line 2,326: Line 2,326:
var tests = $array(2000, 1997, 1996, 1994, 1990, 1980, 1900)
var tests = $array(2000, 1997, 1996, 1994, 1990, 1980, 1900)
var cnt = $asize(tests)
var cnt = $asize(tests)
while (cnt -= 1) >= 0 $print(tests[cnt], if leapyear(tests[cnt]) " is" else " is not", " a leapyear", "\n")</lang>
while (cnt -= 1) >= 0 $print(tests[cnt], if leapyear(tests[cnt]) " is" else " is not", " a leapyear", "\n")</syntaxhighlight>


{{out}}
{{out}}
Line 2,341: Line 2,341:
=={{header|Nemerle}}==
=={{header|Nemerle}}==
Demonstrating implementation as well as use of standard library function.
Demonstrating implementation as well as use of standard library function.
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;
using Nemerle.Assertions;
using Nemerle.Assertions;
Line 2,377: Line 2,377:
DateTime.IsLeapYear(DateTime.Now.Year));
DateTime.IsLeapYear(DateTime.Now.Year));
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>2000 is a leap year: True
<pre>2000 is a leap year: True
Line 2,394: Line 2,394:
prior to the Gregorian cut-over and leap-year rules in the Julian calendar
prior to the Gregorian cut-over and leap-year rules in the Julian calendar
are different to those for the Gregorian calendar.
are different to those for the Gregorian calendar.
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */


options replace format comments java crossref savelog symbols nobinary
options replace format comments java crossref savelog symbols nobinary
Line 2,438: Line 2,438:


method isFalse public constant binary returns boolean
method isFalse public constant binary returns boolean
return \isTrue</lang>
return \isTrue</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,449: Line 2,449:


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import times
<syntaxhighlight lang="nim">import times
let year = 1980
let year = 1980
echo isLeapYear(year)
echo isLeapYear(year)
Line 2,460: Line 2,460:
else: year mod 4 == 0
else: year mod 4 == 0


echo isLeapYear2(year)</lang>
echo isLeapYear2(year)</syntaxhighlight>
{{out}}
{{out}}
<pre>true
<pre>true
Line 2,466: Line 2,466:


=={{header|NS-HUBASIC}}==
=={{header|NS-HUBASIC}}==
<lang NS-HUBASIC>10 INPUT "ENTER A NUMBER, AND I'LL DETECT IF IT'S A LEAP YEAR OR NOT. ",A
<syntaxhighlight lang="ns-hubasic">10 INPUT "ENTER A NUMBER, AND I'LL DETECT IF IT'S A LEAP YEAR OR NOT. ",A
20 IF A-(A/100)*100=0 AND A-(A/400)*400<>0 THEN RESULT$="NOT "
20 IF A-(A/100)*100=0 AND A-(A/400)*400<>0 THEN RESULT$="NOT "
30 PRINT "THAT'S "RESULT$"A LEAP YEAR."</lang>
30 PRINT "THAT'S "RESULT$"A LEAP YEAR."</syntaxhighlight>


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<lang oberon2>
<syntaxhighlight lang="oberon2">
PROCEDURE IsLeapYear(year: INTEGER): BOOLEAN;
PROCEDURE IsLeapYear(year: INTEGER): BOOLEAN;
BEGIN
BEGIN
Line 2,488: Line 2,488:
END
END
END IsLeapYear;
END IsLeapYear;
</syntaxhighlight>
</lang>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>bundle Default {
<syntaxhighlight lang="objeck">bundle Default {
class LeapYear {
class LeapYear {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 2,517: Line 2,517:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>let is_leap_year ~year =
<syntaxhighlight lang="ocaml">let is_leap_year ~year =
if (year mod 100) = 0
if (year mod 100) = 0
then (year mod 400) = 0
then (year mod 400) = 0
else (year mod 4) = 0</lang>
else (year mod 4) = 0</syntaxhighlight>
Using Unix Time functions:
Using Unix Time functions:
<lang ocaml>let is_leap_year ~year =
<syntaxhighlight lang="ocaml">let is_leap_year ~year =
let tm =
let tm =
Unix.mktime {
Unix.mktime {
Line 2,534: Line 2,534:
}
}
in
in
(tm.Unix.tm_mday = 29)</lang>
(tm.Unix.tm_mday = 29)</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>Date.IsLeapYear(2000)</lang>
<syntaxhighlight lang="oforth">Date.IsLeapYear(2000)</syntaxhighlight>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<syntaxhighlight lang="oorexx">
<lang ooRexx>
::routine isLeapYear
::routine isLeapYear
use arg year
use arg year
d = .datetime~new(year, 1, 1)
d = .datetime~new(year, 1, 1)
return d~isLeapYear
return d~isLeapYear
</syntaxhighlight>
</lang>


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
The DATE function converts month, day, year integers to a date data type and will set the error status if invalid values are passed.
The DATE function converts month, day, year integers to a date data type and will set the error status if invalid values are passed.
<lang progress>FUNCTION isLeapYear RETURNS LOGICAL (
<syntaxhighlight lang="progress">FUNCTION isLeapYear RETURNS LOGICAL (
i_iyear AS INTEGER
i_iyear AS INTEGER
):
):
Line 2,565: Line 2,565:
1997 isLeapYear( 1997 ) SKIP
1997 isLeapYear( 1997 ) SKIP
2000 isLeapYear( 2000 )
2000 isLeapYear( 2000 )
VIEW-AS ALERT-BOX.</lang>
VIEW-AS ALERT-BOX.</syntaxhighlight>


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>declare
<syntaxhighlight lang="oz">declare
fun {IsLeapYear Year}
fun {IsLeapYear Year}
case Year mod 100 of 0 then
case Year mod 100 of 0 then
Line 2,583: Line 2,583:
{System.showInfo Y#" is NOT a leap year."}
{System.showInfo Y#" is NOT a leap year."}
end
end
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>1900 is NOT a leap year.
<pre>1900 is NOT a leap year.
Line 2,591: Line 2,591:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>isLeap(n)={
<syntaxhighlight lang="parigp">isLeap(n)={
if(n%400==0, return(1));
if(n%400==0, return(1));
if(n%100==0, return(0));
if(n%100==0, return(0));
n%4==0
n%4==0
};</lang>
};</syntaxhighlight>


Alternate version:
Alternate version:
<lang parigp>isLeap(n)=!(n%if(n%100,4,400))</lang>
<syntaxhighlight lang="parigp">isLeap(n)=!(n%if(n%100,4,400))</syntaxhighlight>


{{works with|PARI/GP|2.6.0 and above}}
{{works with|PARI/GP|2.6.0 and above}}
<lang parigp>isLeap(n)={
<syntaxhighlight lang="parigp">isLeap(n)={
if(n%4,0,
if(n%4,0,
n%100,1,
n%100,1,
n%400,0,1
n%400,0,1
)
)
};</lang>
};</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free Pascal}}
{{works with|Free Pascal}}
<lang pascal>program LeapYear;
<syntaxhighlight lang="pascal">program LeapYear;
uses
uses
sysutils;//includes isLeapYear
sysutils;//includes isLeapYear
Line 2,626: Line 2,626:
TestYear(2100);
TestYear(2100);
TestYear(1904);
TestYear(1904);
end.</lang>
end.</syntaxhighlight>
Output:
Output:
<pre>1900 is NO leap year
<pre>1900 is NO leap year
Line 2,634: Line 2,634:


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>sub isleap {
<syntaxhighlight lang="perl">sub isleap {
my $year = shift;
my $year = shift;
if ($year % 100 == 0) {
if ($year % 100 == 0) {
Line 2,640: Line 2,640:
}
}
return ($year % 4 == 0);
return ($year % 4 == 0);
}</lang>
}</syntaxhighlight>


Or more concisely:
Or more concisely:


<lang Perl>sub isleap { !($_[0] % 100) ? !($_[0] % 400) : !($_[0] % 4) }</lang>
<syntaxhighlight lang="perl">sub isleap { !($_[0] % 100) ? !($_[0] % 400) : !($_[0] % 4) }</syntaxhighlight>


Alternatively, using functions/methods from CPAN modules:
Alternatively, using functions/methods from CPAN modules:


<lang Perl>use Date::Manip;
<syntaxhighlight lang="perl">use Date::Manip;
print Date_LeapYear(2000);
print Date_LeapYear(2000);


Line 2,657: Line 2,657:
use DateTime;
use DateTime;
my $date = DateTime->new(year => 2000);
my $date = DateTime->new(year => 2000);
print $date->is_leap_year();</lang>
print $date->is_leap_year();</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Available as an auto-include, implemented as:
Available as an auto-include, implemented as:
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #7060A8;">is_leap_year</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #7060A8;">is_leap_year</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php
function isLeapYear($year) {
function isLeapYear($year) {
if ($year % 100 == 0) {
if ($year % 100 == 0) {
Line 2,674: Line 2,674:
}
}
return ($year % 4 == 0);
return ($year % 4 == 0);
}</lang>
}</syntaxhighlight>
With <code>date('L')</code>:
With <code>date('L')</code>:
<lang php><?php
<syntaxhighlight lang="php"><?php
function isLeapYear($year) {
function isLeapYear($year) {
return (date('L', mktime(0, 0, 0, 2, 1, $year)) === '1')
return (date('L', mktime(0, 0, 0, 2, 1, $year)) === '1')
}</lang>
}</syntaxhighlight>


=={{header|Picat}}==
=={{header|Picat}}==
<lang Picat>go =>
<syntaxhighlight lang="picat">go =>
foreach(Y in [1600,1700,1899,1900,2000,2006,2012])
foreach(Y in [1600,1700,1899,1900,2000,2006,2012])
println(Y=cond(leap_year(Y),leap_year,not_leap_year))
println(Y=cond(leap_year(Y),leap_year,not_leap_year))
Line 2,691: Line 2,691:
(Year mod 4 == 0, Year mod 100 != 0)
(Year mod 4 == 0, Year mod 100 != 0)
;
;
Year mod 400 == 0. </lang>
Year mod 400 == 0. </syntaxhighlight>


{{out}}
{{out}}
Line 2,703: Line 2,703:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de isLeapYear (Y)
<syntaxhighlight lang="picolisp">(de isLeapYear (Y)
(bool (date Y 2 29)) )</lang>
(bool (date Y 2 29)) )</syntaxhighlight>
{{out}}
{{out}}
<pre>: (isLeapYear 2010)
<pre>: (isLeapYear 2010)
Line 2,719: Line 2,719:


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>dcl mod builtin;
<syntaxhighlight lang="pli">dcl mod builtin;
dcl year fixed bin (31);
dcl year fixed bin (31);


Line 2,729: Line 2,729:
else
else
put skip edit(year, 'is not a leap year') (p'9999b', a);
put skip edit(year, 'is not a leap year') (p'9999b', a);
end;</lang>
end;</syntaxhighlight>


{{out}}
{{out}}
Line 2,743: Line 2,743:


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang pli>100H: /* DETERMINE WHETHER SOME YEARS ARE LEAP YEARS OR NOT */
<syntaxhighlight lang="pli">100H: /* DETERMINE WHETHER SOME YEARS ARE LEAP YEARS OR NOT */


/* CP/M BDOS SYSTEM CALL */
/* CP/M BDOS SYSTEM CALL */
Line 2,786: Line 2,786:
END;
END;


EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,807: Line 2,807:


=={{header|PostScript}}==
=={{header|PostScript}}==
<lang postscript>/isleapyear {
<syntaxhighlight lang="postscript">/isleapyear {
dup dup
dup dup
4 mod 0 eq % needs to be divisible by 4
4 mod 0 eq % needs to be divisible by 4
Line 2,816: Line 2,816:
400 mod 0 eq % or by 400
400 mod 0 eq % or by 400
or
or
} def</lang>
} def</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>$Year = 2016
<syntaxhighlight lang="powershell">$Year = 2016
[System.DateTime]::IsLeapYear( $Year )</lang>
[System.DateTime]::IsLeapYear( $Year )</syntaxhighlight>


=={{header|Prolog}}==
=={{header|Prolog}}==
{{Works with|SWI-Prolog}}
{{Works with|SWI-Prolog}}
<lang Prolog>leap_year(L) :-
<syntaxhighlight lang="prolog">leap_year(L) :-
partition(is_leap_year, L, LIn, LOut),
partition(is_leap_year, L, LIn, LOut),
format('leap years : ~w~n', [LIn]),
format('leap years : ~w~n', [LIn]),
Line 2,833: Line 2,833:
R100 is Year mod 100,
R100 is Year mod 100,
R400 is Year mod 400,
R400 is Year mod 400,
( (R4 = 0, R100 \= 0); R400 = 0).</lang>
( (R4 = 0, R100 \= 0); R400 = 0).</syntaxhighlight>
{{out}}
{{out}}
<lang Prolog> ?- leap_year([1900,1994,1996,1997,2000 ]).
<syntaxhighlight lang="prolog"> ?- leap_year([1900,1994,1996,1997,2000 ]).
leap years : [1996,2000]
leap years : [1996,2000]
not leap years : [1900,1994,1997]
not leap years : [1900,1994,1997]
L = [1900,1994,1996,1997,2000].</lang>
L = [1900,1994,1996,1997,2000].</syntaxhighlight>


There is an handy builtin that simplifies a lot, ending up in a simple query:
There is an handy builtin that simplifies a lot, ending up in a simple query:


<syntaxhighlight lang="prolog">
<lang Prolog>
?- findall(Y, (between(1990,2030,Y),day_of_the_year(date(Y,12,31),366)), L).
?- findall(Y, (between(1990,2030,Y),day_of_the_year(date(Y,12,31),366)), L).
L = [1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028].
L = [1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028].
</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Procedure isLeapYear(Year)
<syntaxhighlight lang="purebasic">Procedure isLeapYear(Year)
If (Year%4=0 And Year%100) Or Year%400=0
If (Year%4=0 And Year%100) Or Year%400=0
ProcedureReturn #True
ProcedureReturn #True
Line 2,854: Line 2,854:
ProcedureReturn #False
ProcedureReturn #False
EndIf
EndIf
EndProcedure</lang>
EndProcedure</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import calendar
<syntaxhighlight lang="python">import calendar
calendar.isleap(year)</lang>
calendar.isleap(year)</syntaxhighlight>
or
or
<lang python>def is_leap_year(year):
<syntaxhighlight lang="python">def is_leap_year(year):
if year % 100 == 0:
if year % 100 == 0:
return year % 400 == 0
return year % 400 == 0
return year % 4 == 0</lang>
return year % 4 == 0</syntaxhighlight>
Asking for forgiveness instead of permission:
Asking for forgiveness instead of permission:
<lang python>import datetime
<syntaxhighlight lang="python">import datetime


def is_leap_year(year):
def is_leap_year(year):
Line 2,872: Line 2,872:
except ValueError:
except ValueError:
return False
return False
return True</lang>
return True</syntaxhighlight>


=={{header|Q}}==
=={{header|Q}}==
<lang q>ly:{((0<>x mod 100) | 0=x mod 400) & 0=x mod 4} / Return 1b if x is a leap year; 0b otherwise</lang>
<syntaxhighlight lang="q">ly:{((0<>x mod 100) | 0=x mod 400) & 0=x mod 4} / Return 1b if x is a leap year; 0b otherwise</syntaxhighlight>


=={{header|Quackery}}==
=={{header|Quackery}}==
{{trans|Forth}}
{{trans|Forth}}
<lang Quackery> [ dup 400 mod 0 = iff [ drop true ] done
<syntaxhighlight lang="quackery"> [ dup 400 mod 0 = iff [ drop true ] done
dup 100 mod 0 = iff [ drop false ] done
dup 100 mod 0 = iff [ drop false ] done
4 mod 0 = ] is leap? ( n --> b )</lang>
4 mod 0 = ] is leap? ( n --> b )</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang R>isLeapYear <- function(year) {
<syntaxhighlight lang="r">isLeapYear <- function(year) {
ifelse(year%%100==0, year%%400==0, year%%4==0)
ifelse(year%%100==0, year%%400==0, year%%4==0)
}
}
Line 2,890: Line 2,890:
for (y in c(1900, 1994, 1996, 1997, 2000)) {
for (y in c(1900, 1994, 1996, 1997, 2000)) {
cat(y, ifelse(isLeapYear(y), "is", "isn't"), "a leap year.\n")
cat(y, ifelse(isLeapYear(y), "is", "isn't"), "a leap year.\n")
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,901: Line 2,901:


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>(define (leap-year? y)
<syntaxhighlight lang="racket">(define (leap-year? y)
(and (zero? (modulo y 4)) (or (positive? (modulo y 100)) (zero? (modulo y 400)))))</lang>
(and (zero? (modulo y 4)) (or (positive? (modulo y 100)) (zero? (modulo y 400)))))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|2010.07}}
{{works with|Rakudo|2010.07}}
<lang perl6>say "$year is a {Date.is-leap-year($year) ?? 'leap' !! 'common'} year."</lang>
<syntaxhighlight lang="raku" line>say "$year is a {Date.is-leap-year($year) ?? 'leap' !! 'common'} year."</syntaxhighlight>
In Rakudo 2010.07, <code>Date.is-leap-year</code> is implemented as
In Rakudo 2010.07, <code>Date.is-leap-year</code> is implemented as
<lang perl6>multi method is-leap-year($y = $!year) {
<syntaxhighlight lang="raku" line>multi method is-leap-year($y = $!year) {
$y %% 4 and not $y %% 100 or $y %% 400
$y %% 4 and not $y %% 100 or $y %% 400
}</lang>
}</syntaxhighlight>


=={{header|Rapira}}==
=={{header|Rapira}}==
<lang Rapira>fun is_leap_year(year)
<syntaxhighlight lang="rapira">fun is_leap_year(year)
if (year /% 100) = 0 then
if (year /% 100) = 0 then
return (year /% 400) = 0
return (year /% 400) = 0
fi
fi
return (year /% 4) = 0
return (year /% 4) = 0
end</lang>
end</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==
<lang Raven>define is_leap_year use $year
<syntaxhighlight lang="raven">define is_leap_year use $year
$year 100 % 0 = if
$year 100 % 0 = if
$year 400 % 0 =
$year 400 % 0 =
$year 4 % 0 =</lang>
$year 4 % 0 =</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang rebol>leap-year?: func [
<syntaxhighlight lang="rebol">leap-year?: func [
{Returns true if the specified year is a leap year; false otherwise.}
{Returns true if the specified year is a leap year; false otherwise.}
year [date! integer!]
year [date! integer!]
Line 2,942: Line 2,942:
div?: func [n] [zero? year // n]
div?: func [n] [zero? year // n]
to logic! any [all [div? 4 not div? 100] div? 400]
to logic! any [all [div? 4 not div? 100] div? 400]
]</lang>
]</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
<lang Retro>:isLeapYear? (y-f)
<syntaxhighlight lang="retro">:isLeapYear? (y-f)
dup #400 mod n:zero? [ drop #-1 #0 ] [ #1 ] choose 0; drop
dup #400 mod n:zero? [ drop #-1 #0 ] [ #1 ] choose 0; drop
dup #100 mod n:zero? [ drop #0 #0 ] [ #1 ] choose 0; drop
dup #100 mod n:zero? [ drop #0 #0 ] [ #1 ] choose 0; drop
#4 mod n:zero? ;</lang>
#4 mod n:zero? ;</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
===local variables===
===local variables===
<lang rexx>leapyear: procedure; parse arg yr
<syntaxhighlight lang="rexx">leapyear: procedure; parse arg yr
return yr//400==0 | (yr//100\==0 & yr//4==0)</lang>
return yr//400==0 | (yr//100\==0 & yr//4==0)</syntaxhighlight>


===with short-circuit===
===with short-circuit===
The REXX language doesn't support short-circuits, so here is a version that does a short-circuit.
The REXX language doesn't support short-circuits, so here is a version that does a short-circuit.
<lang rexx>leapyear: procedure; parse arg yr
<syntaxhighlight lang="rexx">leapyear: procedure; parse arg yr
if yr//4\==0 then return 0 /*Not ÷ by 4? Not a leap year.*/
if yr//4\==0 then return 0 /*Not ÷ by 4? Not a leap year.*/
return yr//400==0 | yr//100\==0</lang>
return yr//400==0 | yr//100\==0</syntaxhighlight>


===no local variables===
===no local variables===
This version doesn't need a PROCEDURE to hide local variable(s) &nbsp; [because there aren't any local variables],
This version doesn't need a PROCEDURE to hide local variable(s) &nbsp; [because there aren't any local variables],
<br>but it does invoke the &nbsp; '''ARG''' &nbsp; BIF multiple times.
<br>but it does invoke the &nbsp; '''ARG''' &nbsp; BIF multiple times.
<lang rexx>leapyear: if arg(1)//4\==0 then return 0
<syntaxhighlight lang="rexx">leapyear: if arg(1)//4\==0 then return 0
return arg(1)//400==0 | arg(1)//100\==0</lang>
return arg(1)//400==0 | arg(1)//100\==0</syntaxhighlight>


===handles 2 digit year===
===handles 2 digit year===
Line 2,971: Line 2,971:
<br>the current century is assumed &nbsp; (i.e., &nbsp; no ''year'' windowing).
<br>the current century is assumed &nbsp; (i.e., &nbsp; no ''year'' windowing).
<br><br>If a year below 100 is to be used, the year should have leading zeroes added (to make it four digits).
<br><br>If a year below 100 is to be used, the year should have leading zeroes added (to make it four digits).
<lang rexx>leapyear: procedure; parse arg y /*year could be: Y, YY, YYY, YYYY*/
<syntaxhighlight lang="rexx">leapyear: procedure; parse arg y /*year could be: Y, YY, YYY, YYYY*/
if y//4\==0 then return 0 /*Not ÷ by 4? Not a leap year.*/
if y//4\==0 then return 0 /*Not ÷ by 4? Not a leap year.*/
if length(y)==2 then y=left(date('S'),2)y /*adjust for a 2─digit YY year.*/
if length(y)==2 then y=left(date('S'),2)y /*adjust for a 2─digit YY year.*/
return y//100\==0 | y//400==0 /*apply 100 and 400 year rule. */</lang>
return y//100\==0 | y//400==0 /*apply 100 and 400 year rule. */</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
give year
give year
leap = isLeapYear(year)
leap = isLeapYear(year)
Line 2,988: Line 2,988:
but (year % 4) = 0 return true
but (year % 4) = 0 return true
else return false ok
else return false ok
</syntaxhighlight>
</lang>


=={{header|RPG}}==
=={{header|RPG}}==
Line 2,994: Line 2,994:
{{works with|RPGIII|}}
{{works with|RPGIII|}}


<lang RPG> C*0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++
<syntaxhighlight lang="rpg"> C*0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++
C *ENTRY PLIST
C *ENTRY PLIST
C PARM YEAR 40 input (year)
C PARM YEAR 40 input (year)
Line 3,020: Line 3,020:
C*
C*
C DONE TAG
C DONE TAG
C SETON LR</lang>
C SETON LR</syntaxhighlight>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>require 'date'
<syntaxhighlight lang="ruby">require 'date'


Date.leap?(year)</lang>
Date.leap?(year)</syntaxhighlight>


The leap? method is aliased as gregorian_leap? And yes, there is a julian_leap? method.
The leap? method is aliased as gregorian_leap? And yes, there is a julian_leap? method.


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>if date$("02/29/" + mid$(date$("mm/dd/yyyy"),7,4)) then print "leap year" else print "not"</lang>
<syntaxhighlight lang="runbasic">if date$("02/29/" + mid$(date$("mm/dd/yyyy"),7,4)) then print "leap year" else print "not"</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn is_leap(year: i32) -> bool {
<syntaxhighlight lang="rust">fn is_leap(year: i32) -> bool {
let factor = |x| year % x == 0;
let factor = |x| year % x == 0;
factor(4) && (!factor(100) || factor(400))
factor(4) && (!factor(100) || factor(400))
}</lang>
}</syntaxhighlight>


=={{header|S-BASIC}}==
=={{header|S-BASIC}}==
Since S-BASIC has no MOD operator or function, we have to supply one.
Since S-BASIC has no MOD operator or function, we have to supply one.
<lang basic>
<syntaxhighlight lang="basic">
rem - compute p mod q
rem - compute p mod q
function mod(p, q = integer) = integer
function mod(p, q = integer) = integer
Line 3,069: Line 3,069:


end
end
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,091: Line 3,091:
By default, [http://docs.oracle.com/javase/7/docs/api/index.html?java/util/GregorianCalendar.html java.util.GregorianCalendar] switches from Julian calendar to Gregorian calendar at 15 October 1582.
By default, [http://docs.oracle.com/javase/7/docs/api/index.html?java/util/GregorianCalendar.html java.util.GregorianCalendar] switches from Julian calendar to Gregorian calendar at 15 October 1582.


<lang scala>//use Java's calendar class
<syntaxhighlight lang="scala">//use Java's calendar class
new java.util.GregorianCalendar().isLeapYear(year)</lang>
new java.util.GregorianCalendar().isLeapYear(year)</syntaxhighlight>


===JDK 8===
===JDK 8===
Using JSR-310 java.time.
Using JSR-310 java.time.
<lang scala>java.time.LocalDate.ofYearDay(year, 1).isLeapYear()</lang>
<syntaxhighlight lang="scala">java.time.LocalDate.ofYearDay(year, 1).isLeapYear()</syntaxhighlight>


===Implementation===
===Implementation===
Line 3,102: Line 3,102:
For proleptic Gregorian calendar:
For proleptic Gregorian calendar:


<lang scala>def isLeapYear(year:Int)=if (year%100==0) year%400==0 else year%4==0;
<syntaxhighlight lang="scala">def isLeapYear(year:Int)=if (year%100==0) year%400==0 else year%4==0;


//or use Java's calendar class
//or use Java's calendar class
Line 3,109: Line 3,109:
c.setGregorianChange(new java.util.Date(Long.MinValue))
c.setGregorianChange(new java.util.Date(Long.MinValue))
c.isLeapYear(year)
c.isLeapYear(year)
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>(define (leap-year? n)
<syntaxhighlight lang="scheme">(define (leap-year? n)
(apply (lambda (a b c) (or a (and (not b) c)))
(apply (lambda (a b c) (or a (and (not b) c)))
(map (lambda (m) (zero? (remainder n m)))
(map (lambda (m) (zero? (remainder n m)))
'(400 100 4))))</lang>
'(400 100 4))))</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
This function is part of the "time.s7i" library. It returns TRUE if the year is a leap year in the Gregorian calendar.
This function is part of the "time.s7i" library. It returns TRUE if the year is a leap year in the Gregorian calendar.
<lang seed7>const func boolean: isLeapYear (in integer: year) is
<syntaxhighlight lang="seed7">const func boolean: isLeapYear (in integer: year) is
return (year rem 4 = 0 and year rem 100 <> 0) or year rem 400 = 0;</lang>
return (year rem 4 = 0 and year rem 100 <> 0) or year rem 400 = 0;</syntaxhighlight>
Original source: [http://seed7.sourceforge.net/algorith/date.htm#isLeapYear]
Original source: [http://seed7.sourceforge.net/algorith/date.htm#isLeapYear]


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func isleap(year) {
<syntaxhighlight lang="ruby">func isleap(year) {
if (year %% 100) {
if (year %% 100) {
return (year %% 400);
return (year %% 400);
}
}
return (year %% 4);
return (year %% 4);
}</lang>
}</syntaxhighlight>


or a little bit simpler:
or a little bit simpler:
<lang ruby>func isleap(year) { year %% 100 ? (year %% 400) : (year %% 4) };</lang>
<syntaxhighlight lang="ruby">func isleap(year) { year %% 100 ? (year %% 400) : (year %% 4) };</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Smalltalk has a built-in method named <tt>isLeapYear</tt>:
Smalltalk has a built-in method named <tt>isLeapYear</tt>:
<lang smalltalk>
<syntaxhighlight lang="smalltalk">
Date today isLeapYear.
Date today isLeapYear.
</syntaxhighlight>
</lang>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Predicate leap( ) succeeds/fails, returns nil.
Predicate leap( ) succeeds/fails, returns nil.
<lang SNOBOL4> define('leap(yr)') :(end_leap)
<syntaxhighlight lang="snobol4"> define('leap(yr)') :(end_leap)
leap eq(remdr(yr,400),0) :s(return)
leap eq(remdr(yr,400),0) :s(return)
eq(remdr(yr,100),0) :s(freturn)
eq(remdr(yr,100),0) :s(freturn)
Line 3,154: Line 3,154:
yr = '1900'; eval(test)
yr = '1900'; eval(test)
yr = '2000'; eval(test)
yr = '2000'; eval(test)
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>0: 1066
<pre>0: 1066
Line 3,162: Line 3,162:


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>fun isLeapYear y =
<syntaxhighlight lang="sml">fun isLeapYear y =
y mod (if y mod 100 = 0 then 400 else 4) = 0</lang>
y mod (if y mod 100 = 0 then 400 else 4) = 0</syntaxhighlight>


=={{header|Stata}}==
=={{header|Stata}}==
Line 3,169: Line 3,169:
Given a dataset with a "year" variable, generate a variable "leap" which is 1 for a leap year, 0 otherwise.
Given a dataset with a "year" variable, generate a variable "leap" which is 1 for a leap year, 0 otherwise.


<lang stata>gen leap = mod(year,400)==0 | mod(year,4)==0 & mod(year,100)!=0</lang>
<syntaxhighlight lang="stata">gen leap = mod(year,400)==0 | mod(year,4)==0 & mod(year,100)!=0</syntaxhighlight>


See also the article '''[https://www.stata.com/support/faqs/data-management/leap-year-indicators/ How do I identify leap years in Stata?]''' by Nicholas J. Cox in Stata FAQ.
See also the article '''[https://www.stata.com/support/faqs/data-management/leap-year-indicators/ How do I identify leap years in Stata?]''' by Nicholas J. Cox in Stata FAQ.


=={{header|Swift}}==
=={{header|Swift}}==
<lang Swift>func isLeapYear(year: Int) -> Bool {
<syntaxhighlight lang="swift">func isLeapYear(year: Int) -> Bool {
return year.isMultiple(of: 100) ? year.isMultiple(of: 400) : year.isMultiple(of: 4)
return year.isMultiple(of: 100) ? year.isMultiple(of: 400) : year.isMultiple(of: 4)
}
}
Line 3,180: Line 3,180:
[1900, 1994, 1996, 1997, 2000].forEach { year in
[1900, 1994, 1996, 1997, 2000].forEach { year in
print("\(year): \(isLeapYear(year: year) ? "YES" : "NO")")
print("\(year): \(isLeapYear(year: year) ? "YES" : "NO")")
} </lang>
} </syntaxhighlight>
{{out}}
{{out}}
<pre>1900: NO
<pre>1900: NO
Line 3,191: Line 3,191:
=={{header|Tcl}}==
=={{header|Tcl}}==
The "classic" modulo comparison:
The "classic" modulo comparison:
<lang tcl>proc isleap1 {year} {
<syntaxhighlight lang="tcl">proc isleap1 {year} {
return [expr {($year % 4 == 0) && (($year % 100 != 0) || ($year % 400 == 0))}]
return [expr {($year % 4 == 0) && (($year % 100 != 0) || ($year % 400 == 0))}]
}
}
Line 3,197: Line 3,197:
isleap1 1989 ;# => 0
isleap1 1989 ;# => 0
isleap1 1900 ;# => 0
isleap1 1900 ;# => 0
isleap1 2000 ;# => 1</lang>
isleap1 2000 ;# => 1</syntaxhighlight>
Does Feb 29 exist in the given year? If not a leap year, the clock command will return "03-01". (This code will switch to the Julian calendar for years before 1582.)
Does Feb 29 exist in the given year? If not a leap year, the clock command will return "03-01". (This code will switch to the Julian calendar for years before 1582.)
<lang tcl>proc isleap2 year {
<syntaxhighlight lang="tcl">proc isleap2 year {
return [expr {[clock format [clock scan "$year-02-29" -format "%Y-%m-%d"] -format "%m-%d"] eq "02-29"}]
return [expr {[clock format [clock scan "$year-02-29" -format "%Y-%m-%d"] -format "%m-%d"] eq "02-29"}]
}
}
Line 3,205: Line 3,205:
isleap2 1989 ;# => 0
isleap2 1989 ;# => 0
isleap2 1900 ;# => 0
isleap2 1900 ;# => 0
isleap2 2000 ;# => 1</lang>
isleap2 2000 ;# => 1</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE TUSCRIPT
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
LOOP year="1900'1994'1996'1997'2000",txt=""
LOOP year="1900'1994'1996'1997'2000",txt=""
SET dayoftheweek=DATE(number,29,2,year,number)
SET dayoftheweek=DATE(number,29,2,year,number)
IF (dayoftheweek==0) SET txt="not "
IF (dayoftheweek==0) SET txt="not "
PRINT year," is ",txt,"a leap year"
PRINT year," is ",txt,"a leap year"
ENDLOOP</lang>
ENDLOOP</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,225: Line 3,225:
=={{header|uBasic/4tH}}==
=={{header|uBasic/4tH}}==
{{trans|BBC BASIC}}
{{trans|BBC BASIC}}
<lang>DO
<syntaxhighlight lang="text">DO
INPUT "Enter a year: "; y
INPUT "Enter a year: "; y
IF FUNC(_FNleap(y)) THEN
IF FUNC(_FNleap(y)) THEN
Line 3,236: Line 3,236:


_FNleap Param (1)
_FNleap Param (1)
RETURN ((a@ % 4 = 0) * ((a@ % 400 = 0) + (a@ % 100 # 0)))</lang>
RETURN ((a@ % 4 = 0) * ((a@ % 400 = 0) + (a@ % 100 # 0)))</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Original Bourne:
Original Bourne:
<lang sh>leap() {
<syntaxhighlight lang="sh">leap() {
if expr $1 % 4 >/dev/null; then return 1; fi
if expr $1 % 4 >/dev/null; then return 1; fi
if expr $1 % 100 >/dev/null; then return 0; fi
if expr $1 % 100 >/dev/null; then return 0; fi
if expr $1 % 400 >/dev/null; then return 1; fi
if expr $1 % 400 >/dev/null; then return 1; fi
return 0;
return 0;
}</lang>
}</syntaxhighlight>


Using GNU date(1):
Using GNU date(1):
<lang sh>leap() {
<syntaxhighlight lang="sh">leap() {
date -d "$1-02-29" >/dev/null 2>&1;
date -d "$1-02-29" >/dev/null 2>&1;
}</lang>
}</syntaxhighlight>


Defining a bash function <tt>is_leap</tt> which accepts a YEAR argument, and uses no IO redirection, nor any extra processes.
Defining a bash function <tt>is_leap</tt> which accepts a YEAR argument, and uses no IO redirection, nor any extra processes.
<lang sh>is_leap() {
<syntaxhighlight lang="sh">is_leap() {
local year=$(( 10#${1:?'Missing year'} ))
local year=$(( 10#${1:?'Missing year'} ))
(( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )) && return 0
(( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )) && return 0
return 1
return 1
}</lang>
}</syntaxhighlight>


Using the cal command: ''(note that this invokes two processes with IO piped between them and is relatively heavyweight compared to the above shell functions: leap and is_leap)''
Using the cal command: ''(note that this invokes two processes with IO piped between them and is relatively heavyweight compared to the above shell functions: leap and is_leap)''
Line 3,265: Line 3,265:
<!-- actually, it *is* correct for dates from 1752 and after. Since the Gregorian calendar didn't exist prior to that date,
<!-- actually, it *is* correct for dates from 1752 and after. Since the Gregorian calendar didn't exist prior to that date,
it doesn't make sense to hold this task accountable for years prior -->
it doesn't make sense to hold this task accountable for years prior -->
<lang sh>leap() {
<syntaxhighlight lang="sh">leap() {
cal 02 $1 | grep -q 29
cal 02 $1 | grep -q 29
}
}
</syntaxhighlight>
</lang>


=={{header|Ursa}}==
=={{header|Ursa}}==
This program takes a year as a command line argument.
This program takes a year as a command line argument.
<lang ursa>decl int year
<syntaxhighlight lang="ursa">decl int year
set year (int args<1>)
set year (int args<1>)
if (= (mod year 4) 0)
if (= (mod year 4) 0)
Line 3,282: Line 3,282:
else
else
out year " is not a leap year" endl console
out year " is not a leap year" endl console
end if</lang>
end if</syntaxhighlight>
Output in Bash:
Output in Bash:
<pre>$ ursa leapyear.u 1900
<pre>$ ursa leapyear.u 1900
Line 3,290: Line 3,290:


=={{header|Vala}}==
=={{header|Vala}}==
<lang Vala>void main() {
<syntaxhighlight lang="vala">void main() {
DateYear[] years = { 1900, 1994, 1996, 1997, 2000 };
DateYear[] years = { 1900, 1994, 1996, 1997, 2000 };
foreach ( DateYear year in years ) {
foreach ( DateYear year in years ) {
Line 3,296: Line 3,296:
print (@"$year is $(status)a leap year.\n");
print (@"$year is $(status)a leap year.\n");
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,307: Line 3,307:


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Public Function Leap_year(year As Integer) As Boolean
<syntaxhighlight lang="vb">Public Function Leap_year(year As Integer) As Boolean
Leap_year = (Month(DateSerial(year, 2, 29)) = 2)
Leap_year = (Month(DateSerial(year, 2, 29)) = 2)
End Function</lang>
End Function</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function IsLeapYear(yr)
Function IsLeapYear(yr)
IsLeapYear = False
IsLeapYear = False
Line 3,330: Line 3,330:
End If
End If
Next
Next
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 3,343: Line 3,343:


=={{header|Vedit macro language}}==
=={{header|Vedit macro language}}==
<lang vedit>while (#1 = Get_Num("Year: ")) {
<syntaxhighlight lang="vedit">while (#1 = Get_Num("Year: ")) {
#2 = (#1 % 4 == 0) && ((#1 % 100 != 0) || (#1 % 400 == 0))
#2 = (#1 % 4 == 0) && ((#1 % 100 != 0) || (#1 % 400 == 0))
if (#2) {
if (#2) {
Line 3,350: Line 3,350:
Message(" is not leap year\n")
Message(" is not leap year\n")
}
}
}</lang>
}</syntaxhighlight>


The following version requires Vedit 6.10 or later:
The following version requires Vedit 6.10 or later:
<lang vedit>while (#1 = Get_Num("Year: ")) {
<syntaxhighlight lang="vedit">while (#1 = Get_Num("Year: ")) {
if (Is_Leap_Year(#1)) {
if (Is_Leap_Year(#1)) {
Message(" is leap year\n")
Message(" is leap year\n")
Line 3,359: Line 3,359:
Message(" is not leap year\n")
Message(" is not leap year\n")
}
}
}</lang>
}</syntaxhighlight>


=={{header|Visual Basic}}==
=={{header|Visual Basic}}==
{{works with|Visual Basic|VB6 Standard}}
{{works with|Visual Basic|VB6 Standard}}
<syntaxhighlight lang="vb">
<lang vb>
Public Function IsLeapYear1(ByVal theYear As Integer) As Boolean
Public Function IsLeapYear1(ByVal theYear As Integer) As Boolean
'this function utilizes documented behaviour of the built-in DateSerial function
'this function utilizes documented behaviour of the built-in DateSerial function
Line 3,373: Line 3,373:
IsLeapYear2 = IIf(theYear Mod 100 = 0, theYear Mod 400 = 0, theYear Mod 4 = 0)
IsLeapYear2 = IIf(theYear Mod 100 = 0, theYear Mod 400 = 0, theYear Mod 4 = 0)
End Function
End Function
</syntaxhighlight>
</lang>
Testing:
Testing:
<syntaxhighlight lang="vb">
<lang vb>
Sub Main()
Sub Main()
'testing the above functions
'testing the above functions
Line 3,383: Line 3,383:
Next i
Next i
End Sub
End Sub
</syntaxhighlight>
</lang>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Module Module1
<syntaxhighlight lang="vbnet">Module Module1


Sub Main()
Sub Main()
Line 3,395: Line 3,395:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>1900 is not a leap year.
<pre>1900 is not a leap year.
Line 3,403: Line 3,403:


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>fn is_leap(year int) bool {
<syntaxhighlight lang="vlang">fn is_leap(year int) bool {
return year %400 ==0 || (year%4 ==0 && year%100!=0)
return year %400 ==0 || (year%4 ==0 && year%100!=0)
}
}
Line 3,414: Line 3,414:
}
}
}
}
</syntaxhighlight>
</lang>
Returns:
Returns:
<pre>1952
<pre>1952
Line 3,434: Line 3,434:


=={{header|WDTE}}==
=={{header|WDTE}}==
<lang WDTE>let str => import 'strings';
<syntaxhighlight lang="wdte">let str => import 'strings';


let multiple of n => == (% n of) 0;
let multiple of n => == (% n of) 0;
Line 3,443: Line 3,443:
multiple 4 => '';
multiple 4 => '';
default => ' not';
default => ' not';
}) -- io.writeln io.stdout;</lang>
}) -- io.writeln io.stdout;</syntaxhighlight>


=={{header|WebAssembly}}==
=={{header|WebAssembly}}==
First, with syntactic sugar that allows us to put opcode arguments after the opcode itself:
First, with syntactic sugar that allows us to put opcode arguments after the opcode itself:
<lang WebAssembly>(module
<syntaxhighlight lang="webassembly">(module
;; function isLeapYear: returns 1 if its argument (e.g. 2004) is a leap year, 0 otherwise.
;; function isLeapYear: returns 1 if its argument (e.g. 2004) is a leap year, 0 otherwise.
;; Returns year%4==0 and (year%100!=0 or year%400==0)
;; Returns year%4==0 and (year%100!=0 or year%400==0)
Line 3,460: Line 3,460:
)
)
(export "isLeapYear" (func $isLeapYear))
(export "isLeapYear" (func $isLeapYear))
)</lang>
)</syntaxhighlight>


And then the same code, without the syntactic sugar:
And then the same code, without the syntactic sugar:
<lang WebAssembly>(module
<syntaxhighlight lang="webassembly">(module
;; function isLeapYear: returns 1 if its argument (e.g. 2004) is a leap year, 0 otherwise.
;; function isLeapYear: returns 1 if its argument (e.g. 2004) is a leap year, 0 otherwise.
;; Returns year%4==0 and (year%100!=0 or year%400==0)
;; Returns year%4==0 and (year%100!=0 or year%400==0)
Line 3,484: Line 3,484:
)
)
(export "isLeapYear" (func $isLeapYear))
(export "isLeapYear" (func $isLeapYear))
)</lang>
)</syntaxhighlight>


=={{header|Wortel}}==
=={{header|Wortel}}==
<lang wortel>@let {
<syntaxhighlight lang="wortel">@let {
isLeapYear !?{\~%%1H \~%%4H \~%%4}
isLeapYear !?{\~%%1H \~%%4H \~%%4}
!-isLeapYear @range[1900 2000]
!-isLeapYear @range[1900 2000]
}</lang>
}</syntaxhighlight>
Returns:
Returns:
<pre>[1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000]</pre>
<pre>[1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000]</pre>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>var isLeapYear = Fn.new { |y|
<syntaxhighlight lang="ecmascript">var isLeapYear = Fn.new { |y|
return ((y % 4 == 0) && (y % 100!= 0)) || (y % 400 == 0)
return ((y % 4 == 0) && (y % 100!= 0)) || (y % 400 == 0)
}
}
Line 3,507: Line 3,507:
if (c % 15 == 0) System.print()
if (c % 15 == 0) System.print()
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,518: Line 3,518:
=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
Using FASM syntax. Leaf function fits nicely into your program.
Using FASM syntax. Leaf function fits nicely into your program.
<lang asm> align 16
<syntaxhighlight lang="asm"> align 16
; Input year as signed dword in EAX
; Input year as signed dword in EAX
IsLeapYear:
IsLeapYear:
Line 3,534: Line 3,534:
.100:
.100:
test eax,11b
test eax,11b
retn ; 1% : ZF=?, leap year if EAX%400=0</lang>
retn ; 1% : ZF=?, leap year if EAX%400=0</syntaxhighlight>


=={{header|XLISP}}==
=={{header|XLISP}}==
<lang xlisp>(DEFUN LEAP-YEARP (YEAR)
<syntaxhighlight lang="xlisp">(DEFUN LEAP-YEARP (YEAR)
(AND (= (MOD YEAR 4) 0) (OR (/= (MOD YEAR 100) 0) (= (MOD YEAR 400) 0))))
(AND (= (MOD YEAR 4) 0) (OR (/= (MOD YEAR 100) 0) (= (MOD YEAR 400) 0))))


; Test the function
; Test the function
(DISPLAY (MAPCAR LEAP-YEARP '(1600 1640 1800 1928 1979 1990 2000 2004 2005 2016)))</lang>
(DISPLAY (MAPCAR LEAP-YEARP '(1600 1640 1800 1928 1979 1990 2000 2004 2005 2016)))</syntaxhighlight>
{{out}}
{{out}}
<pre>(#T #T () #T () () #T #T () #T)</pre>
<pre>(#T #T () #T () () #T #T () #T)</pre>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func LeapYear(Y); \Return 'true' if Y is a leap year
<syntaxhighlight lang="xpl0">func LeapYear(Y); \Return 'true' if Y is a leap year
int Y;
int Y;
[if rem(Y/100)=0 then return rem(Y/400)=0;
[if rem(Y/100)=0 then return rem(Y/400)=0;
return rem(Y/4)=0;
return rem(Y/4)=0;
];</lang>
];</syntaxhighlight>




=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang yabasic>sub leapyear(year)
<syntaxhighlight lang="yabasic">sub leapyear(year)
if mod(year, 4) <> 0 then return false : fi
if mod(year, 4) <> 0 then return false : fi
if mod(year, 100) = 0 and mod(year, 400) <> 0 then return false : fi
if mod(year, 100) = 0 and mod(year, 400) <> 0 then return false : fi
Line 3,572: Line 3,572:
if mod(year, 4) = 3 then print : fi
if mod(year, 4) = 3 then print : fi
next year
next year
end</lang>
end</syntaxhighlight>




=={{header|Yorick}}==
=={{header|Yorick}}==
This solution is vectorized and can be applied to scalar or array input.
This solution is vectorized and can be applied to scalar or array input.
<lang yorick>func is_leap(y) {
<syntaxhighlight lang="yorick">func is_leap(y) {
return ((y % 4 == 0) & (y % 100 != 0)) | (y % 400 == 0);
return ((y % 4 == 0) & (y % 100 != 0)) | (y % 400 == 0);
}</lang>
}</syntaxhighlight>
Interactive example usage:
Interactive example usage:
<pre>> is_leap(1988)
<pre>> is_leap(1988)
Line 3,587: Line 3,587:


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>Time.Date.isLeapYear(1988) //-->True
<syntaxhighlight lang="zkl">Time.Date.isLeapYear(1988) //-->True
T(1988,1989,1900,2000).apply(Time.Date.isLeapYear)
T(1988,1989,1900,2000).apply(Time.Date.isLeapYear)
//-->L(True,False,False,True)</lang>
//-->L(True,False,False,True)</syntaxhighlight>


{{omit from|GUISS|Only the operator can read the calendar}}
{{omit from|GUISS|Only the operator can read the calendar}}