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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.