Write two functions. The first function, with its file name IsLeapYear.m, accepts a year (as a numerical input argument) and determines whether the year is a leap year. The output argument should be a Boolean variable, which should be true if the year is a leap year and false otherwise. The rules for determining leap years in the Gregorian calendar are: • 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.
The second function, with its file name GetLeapYears.m, generates and outputs a list of leap years. This function should have two input arguments startYear and endYear, which are used to form a sequence of years. For example, if the startYear is 2020, and the endYear is 2120, then the sequence of years would be 2020:2120 (one dimensional array). Use a loop to go through all these years to check if a certain year is a leap year using the IsLeapYear function you have written. This function should have one output argument outputting a list of leap years selected from the array of years between startYear and endYear
This a question I was given and I have written some code. My code doesn't work, and Im just trying to figure out what im missing in the code, if anyone could help direct me?
My two function scripts are here!
function IsLeapYear(Year)%UNTITLED11 Summary of this function goes here
% Detailed explanation goes here
if rem(Year,400) == 0 TOF=1;elseif rem(Year,4)== 0 && rem(Year,100)~= 0 TOF=1;elseif rem(Year,100) == 0 && rem(Year,400)~=0 TOF=0;else TOF=0;endif TOF == 1 disp('True')elseif TOF == 0 disp('False')end----------------------------------------------------------------------------------------------------------------------------------------function [outputArg1] = GetLeapYears(startYear,endYear)%UNTITLED12 Summary of this function goes here
% Detailed explanation goes herem = endYear - startYear;v = [startYear:1:endYear];b = zeros(1,m);for c = 1:mfor a = startYear:endYear b(c) = IsLeapYear(a);endend end
Best Answer