Question: Complete the implementation of the isLeapYear function, which determines whether a given year is a leap year. Definition (wikipedia.org): In the Gregorian calendar, the current

Complete the implementation of the isLeapYear function, which determines whether a given year is a leap year.

Definition (wikipedia.org):

In the Gregorian calendar, the current standard calendar in most of the world, most years that are multiples of 4 are leap years. In each leap year, the month of February has 29 days instead of 28. Adding an extra day to the calendar every four years compensates for the fact that a period of 365 days is shorter than a tropical year by almost 6 hours. This calendar was first used in 1582.

Some exceptions to this basic rule are required since the duration of a tropical year is slightly less than 365.25 days. Over a period of 4 centuries, the accumulated error of adding a leap day every 4 years amounts to about 3 extra days. The Gregorian calendar therefore omits 3 leap days every 400 years, which is the length of its leap cycle. This is done by omitting February 29 in the 3 century years (multiples of 100) that are not also multiples of 400. For example, 1700, 1800, 1900, 2100 and 2200 are common years, but 1600, 2000 and 2400 are leap years.

Input variables:

year A scalar, vector, or matrix, which contains a collection of positive integer year values. All elements of this array are guaranteed to be greater than or equal to 1600.

Output variables:

leap A logical array of the same dimensionality as years, each element of which is 1 if the corresponding element of years is a leap year, or 0 otherwise.

Notes:

No loops or if tests are required to complete this function.

Search "Logical Operations" in the Matlab online documentation for inspiration.

MATLAB has a built-in function, leapyear which performs a similar calculation. You may not use leapyear as part of your solution. However, you are encouraged to use leapyear to test your solution.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!