isLeapYear function

bool isLeapYear(
  1. int year
)

Check if a year is a leap year.

year to check

Implementation

bool isLeapYear(int year) {
  if (year % 4 == 0) {
    if (year % 100 != 0) {
      // leap year - divisible by 4 but not 100
      return true;
    } else if (year % 400 == 0) {
      // leap year - divisible by 4 and 100 and 400
      return true;
    } else {
      // common year - divisible by 4 and 100 but not 400!
      return false;
    }
  } else {
    // common year
    return false;
  }
}