Writing a Leap year function without using the leapyr function
Ältere Kommentare anzeigen
I'm needing a to write a function that takes in a start and end year, and that outputs the leap years in-between those 2 parameters. I feel like I have a good base, but I can't figure out how to include that a year is not a leap year if it is divisible by 100. I have 2 potential ideas as to how to approach the task, but This is what I have so far:
function [] = leapyears(startYear,endYear)
for x=startYear-1:4:endYear-1
fprintf('%i \n', x+1);
if mod(startYear,100)==0
%y=0;
%while y<startYear
%if mod(startYear, 4) == 0 && mod(startYear, 400)==0 && mod(startYear,100)==0
%for x=startYear-1:4:endYear-1
%fprintf('%i \n', x+1);
%end
%y=y+1
%end
end
2 Kommentare
KSSV
am 21 Feb. 2018
You are allowed to use inbuilt function calendar ?
Camila Perez
am 21 Feb. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!