Questions tagged [leap-year]

A leap year is a year containing one additional day, which falls on Feb 29 in the Gregorian calendar.

A leap year (or intercalary or bissextile year) is a year containing one additional day in order to keep the calendar year synchronized with the astronomical or seasonal year.

Because seasons and astronomical events do not repeat in a whole number of days, calendars that have the same number of days in each year, over time, drift with respect to the event that the year is supposed to track. By inserting (or intercalating) an additional day or month into the year, the drift can be corrected. A year that is not a leap year is called a common year.

More about leap years in general are on Wikipedia here.

In computing, we usually are usually referring to the Gregorian Calendar, which inserts an additional day on February 29th into a leap year. A leap year is a year which satisfies both of the following criteria:

  • It is evenly divisible by 4.
  • It is not evenly divisible by 100 unless it is also evenly divisible by 400.

A common implementation of this algorithm is:

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

Leap Year Bugs

Leap years can create bugs in software. This is described in the following post:

What are some examples of leap year bugs?

213 questions
-6
votes
1 answer

Leap Year Calculations using Method

import java.util.Scanner; public class LeapYearTester{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a year"); int year_input = input.nextInt(); // now…
Kukie
  • 1
  • 1
-6
votes
2 answers

Add years, months and days to date C

I am trying to write an algorithm that takes an input of a date ("2000-01-01") and also "y|m|d", where y is the number of years to add to the original date and m and d are the months and days. This algorithm needs to take into account leap years as…
Jamie1596
  • 106
  • 1
  • 1
  • 11
-10
votes
2 answers

Is there a simpler test for leap year in C?

Is there any shorter logic than this to achieve leap year test with fewer conditions? #include int isleap(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } int main() { for (int year = 1600; year…
roh.it
  • 13
  • 5
1 2 3
14
15