Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all; close all; clc
- %Written by: Natalie sursock studentid: 288262728
- %Last modified 22/3/2018
- %Computes number of days in a month given year and month.
- %prompts asking for month and year
- month = input('Please enter month in MM formt (01-12):');
- year = input('Please enter year in YYYY format:');
- %determines days in month given month, taking whether it is a leap year into account
- if month == 01 | month == 03 | month == 05 | month == 07 | month == 08 | month == 10 | month == 12
- days = 31;
- elseif month == 09 | month == 04 | month == 06 | month == 11
- days = 30;
- elseif month == 02;
- end
- if determineleapyear(year) == 1
- days = 29;
- elseif determineleapyear(year) == 0
- days = 28;
- end
- %prints results to the screen ensuring it displays as 2004-02, not 2004-2
- if month <= 9 && month > 0
- fprintf('%.0f-0%.0f has %.0f days.\n',year,month,days);
- elseif month >= 10 && month <= 12
- fprintf('%.0f-%2.0f has %.0f days.\n',year,month,days);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement