A leap year is a year containing an extra day in order to keep the calendar year
ID: 3802050 • Letter: A
Question
A leap year is a year containing an extra day in order to keep the calendar year synchronized with the astronomical year. We generally stick the extra day in February, so that about every 4 years, there are 29 days in February instead of 28 days. More specifically, the rules for assigning leap years are as follows (for the Gregorian calendar): All years evenly divisible by 400 are leap years; Years divisible by 4 but not 100 are leap years; All other years are not leap years. Write a MATLAB script that requests the user input on a starting year (e.g., 2000) and an ending year (e.g.. 3000). and then check whether each year in this range is a leap year. Your program should display some messages in the following format: Year 2000: Leap year Year 2001: Not leap year Year 2999: Not leap year Year 3000: Not leap year at the end, your program should output how many leap years in the above defined range in a message as follows, where the content in the angle brackets should be replaced by the user input and the calculation result of your script: For years between and : leap yearsExplanation / Answer
for year=2000:1:3000
if mod(((year,400) ==0) || (mod(year,4)==0 && mod(year,100)~=0))
fprintf('%i is a leap year ',year)
count=count+1;
else
fprintf('%i is not a leap year ',year)
end
end
fprintf('foryears between 2000 and 3000 %i',count)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.