Question #13639

Write a C++ function named isLeapYear that will take value of a year as a parameter and return whether a year is a leap year or not by returning a boolean value of true or false. A year is a leap year if it is divisible by 4 but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400.

Expert's answer

int isLeapYear(int year){

if (year % 4 == 0 && year % 100 != 0) return true;

if (year % 100 == 0 && year % 400 == 0) return true;

return false;

}

if (year % 4 == 0 && year % 100 != 0) return true;

if (year % 100 == 0 && year % 400 == 0) return true;

return false;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment