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

A year is a leap year if it is divisible by 400 or if it is divisible by 4 but n

ID: 3864938 • Letter: A

Question

A year is a leap year if it is divisible by 400 or if it is divisible by 4 but not by 100. (1) Write a user-defined MATLAB function (named LeapYear) that takes one single- valued input argument and checks whether the value of the input argument is a leap year. If the input argument is a leaf year, the function should return 1; otherwise, it returns 0. (2) Write a MATLAB script file that calls the LeapYear function and prints to the screen all the years between 1900 and 2100 that are leap years. Note that you can use the disp command to print one number per line.

Explanation / Answer

MATLAB code for problem 1:
function [ status ] = leapyear( year )
if mod(year, 4) == 0

status = true;
if mod(year, 100) == 0

status=false;
if mod(year,400)==0

status = true;
end
end
else
status=false;
end

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