I am having trouble compiling this MATLAB code for this assignment, any help wou
ID: 3730459 • Letter: I
Question
I am having trouble compiling this MATLAB code for this assignment, any help would be greatly appreciated:
Write a MATLAB FUNCTION called leapYear.mthat accepts a year and determines whether the year is a leap year. The output should be the variable extra_day, which should be 1 if the year is a leap year and O otherwise. The rules for determining leap years in the Gregorian calendar are as follows: 1. 2. 3. 4. All years evenly divisible by 400 are leap years. Years evenly divisible by 100 but not by 400 are not leap years. Years divisible by 4 but not by 100 are leap years All other years are not leap years For example, the years 1800, 1900, 2100, 2300, and 2500 are not leap years, but 2400 is a leap year.Explanation / Answer
function extra_day = isLeap(year)
extra_day = 1;
if mod(year, 4) == 0
if mod(year, 100) == 0
extra_day=0;
if mod(year,400)==0
extra_day = 1;
end
end
end
end
y = isLeap(1800)
y = isLeap(2100)
y = isLeap(2500)
y = isLeap(2400)
Sample output
function extra_day = isLeap(year)
extra_day = 1;
if mod(year, 4) == 0
if mod(year, 100) == 0
extra_day=0;
if mod(year,400)==0
extra_day = 1;
end
end
end
end
y = isLeap(1800)
y = isLeap(2100)
y = isLeap(2500)
y = isLeap(2400)
Sample output
y = 0 y = 0 y = 0 y = 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.