Advertisement
Guest User

Untitled

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