Writing a Leap year function without using the leapyr function
Afficher commentaires plus anciens
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 commentaires
KSSV
le 21 Fév 2018
You are allowed to use inbuilt function calendar ?
Camila Perez
le 21 Fév 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!