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

Program 3: (Leap Year): Write a Matlab function named leapYear which reads a yea

ID: 3804665 • Letter: P

Question

Program 3: (Leap Year): Write a Matlab function named leapYear which reads a year (integer) from the user and decides whether that year is a leap year. A year is a leap year (and so contains a February 29) if it is divisible by 4. But if the year is also divisible by 100 then it is not a leap year, unless it is divisible by 400. This means that years such as 1992, 1996 are leap years because they are divisible by 4 and are not affected by the rest of the rule which applies to century years such as 1900 and 2000. Century years are not leap years except where they are a multiple of 400. Hence, the years 1700, 1800 and 1900 were not leap years and did not contain a February 29. But the year 2000 was a leap year, the first such century leap year since 1600.

PLEASE I WANT THIS PROGRAM TO BE WRITTEN IN MATLAB SO THAT IT WILL RUN CORRECTLY .

PLEASE I NEED AN ANSWER THAT NO ONE ELSE HAS WRITTEN .

Explanation / Answer

function [ isleap ] = isLeapYear( year )
if mod(year, 400) == 0
isleap = true;
disp("year is a leap year");
elseif mod(year, 4) == 0 && mod(year, 100) ~= 0
isleap = true;
disp("year is a leap year");
else
isleap = false;
disp("year is not leap year");
end
end

% to test the function
isLeapYear(2016)

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