Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that in some parallel universe Matlab exists but the leapyear function is

ID: 3672234 • Letter: A

Question

Assume that in some parallel universe Matlab exists but the leapyear function is missing. Your job is to create an equivalent function. Study the help for the Matlab built-in function called leapyear. Write your own version of the function and name it my_leap_year; make it compatible with the Matlab function. Include help in the function. Hint: the rules for determining leap years are more complex than just every fourth year. Put comments inside your function (not as part of the help) listing the rules and providing a reference for them.

Explanation / Answer

function result = my_leap_year(year)

function [status] = leapyear(year)

if mod(year, 400) == 0

status = true;

else if mod(year, 4 ) == 0 && mod(year, 100) ~=0

status = true;

else

status = false;

end

end