Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that accepts a year and determines whether ornot the year is a l

ID: 1829754 • Letter: W

Question

Write a program that accepts a year and determines whether ornot the year is a leap year. Use the mod function. Theoutput should be the variable extra_day, which should be 1if the year is a leap year and 0 otherwise. The rules fordetermining leap years in the Gregorian calendar are:

1. All years evenly divisible by 400 are leap years.

2. Years evenly divisible by 100 but not by 400 are not leapyears.

3. Years divisible by 4 but not 100 are leap years.

4. All other years are not leap years.

For example, the years 1800, 1900, 2100, 2300, and 2500 are notleap years, but 2400 is a leap year.

can you explain it step by step

Explanation / Answer

Copy this piece of code in a m-file and then executeby changing the values of y: y=1800; if (mod(y,100)==0 && mod(y,400) ~= 0) extra_day=0; elseif mod(y,400)==0 ||(mod(y,4)==0 && mod(y,100) ~=0) extra_day=1;       else extra_day=0;           end extra_day I have simply used the conditions given in the problem to formulatethe if-else statements. Hope this helps :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote