Leap Year | Leap Year Conditions | What is the logic of a Leap Year

Definition of Leap Year: Every year which is exactly divisible by four is a leap year, except the years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the years 1600 and 2000 are.


More about Leap Year in Wikipedia: Leap Year


Leap Year in Programming:

To find a year is leap year or not you can use the below condition:


((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)



I am showing a full code of leap year in JavaScript:

function leapYear(year) {
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
        return "Leap year";
    } else {
        return "Not a leap year";
    }
}

let years = [1600, 1700, 1800, 1900, 2000, 2018, 2020];
for(let i = 0; i < years.length; i++) {
    console.log(leapYear(years[i]));
}










Tags:
Leap year
leap year condition
logic of leap year
leap year solution
leap year in JavaScript
leap year algorithm
how to find leap year easily
29 days in February



Next Post Previous Post
No Comment
Add Comment
comment url