if year is divisible by 400 - then is a leap year if year is divisible by 100 - then is not a leap year if year is divisible by 4 - then is a leap year

17 views (last 30 days)
if year is divisible by 400 - then is a leap year
if year is divisible by 100 - then is not a leap year
if year is divisible by 4 - then is a leap year
All other cases – not leap year
i cannot figure out how to write a if loop for finding out if something is divisibly by anything. i knw there is a function to figure out if a year is a leap year but i have to code it this way specifically

Answers (1)

John D'Errico
John D'Errico on 28 Oct 2019
Hint: What does the mod function tell you? Specifially, if mod(Y,4)==0, what would that tell you? Similarly, what would it tell you if mod(y,100)==0 tell you? Finally, what does this mod(y,400)==0 tell you?
Your homework, not mine, although I would argue I just gave you the answer, IF you think about what I wrote.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!