I would like this code to be converted to a function.
% Convert to function
year=input('Enter specified year(yyyy):');if year>0 if mod(year,400)==0 leap_day=1; else if mod(year,100)==0 leap_day=0; else if mod(year,4)==0 leap_day=1; else leap_day=0; end end endend month =input('Enter specified month(1-12):'); if month>=1 && month <=12 switch (month) case {1,3,5,7,8,10,12} max_day=31; case {4,6,9,11} max_day=30; case {2} max_day=28+leap_day; end fprintf('Enter specified day (1-%d):',max_day); day=input(''); if day>=1 && day <=max_day day_of_year=day; for ii=1:month-1 switch(ii) case {1,3,5,7,8,10,12} day_of_year=day_of_year+31; case {4,6,9,11} day_of_year=day_of_year+30; case {2} day_of_year=day_of_year+28+leap_day; end end
Best Answer