MATLAB: If else condition to determine if a year is a leap year

homeworkif else construct to determine if a year is a leap year or notleap year

Hi there. Given a variable Y which stores a year in the 20th century (between 1901 and 2000), write MATLAB code to create a variable Days and assign it a value of 366 if the year is a leap year or a value of 365 otherwise.

Best Answer

function Days = GetDays (Y)
if isLeapYear(Y)
Days = 365 ;
else
Days = 366 ;
end
Now your problem is to write second function IsLeapYear that returns true for leap years. (hint: see Nitin's answer)
Related Question