disp('Calculates the day of year given the current date');

days = [0 31 28 31 30 31 30 31 31 30 31 30 31];
days = [0 sum(days(1:2)) sum(days(1:3)) sum(days(1:4)) sum(days(1:5)) sum(days(1:6)) ...
          sum(days(1:7)) sum(days(1:8)) sum(days(1:9)) sum(days(1:10)) sum(days(1:11)) ...
          sum(days(1:12))];

month = input('Enter month 1-12: ');
day   = input('Enter day 1-31: ');
year  = input('Enter year yyyy: ');

if mod(year,400) == 0
   leap_day = 1;
elseif mod(year,100) == 0
   leap_day = 0;
elseif mod(year,4) == 0
   leap_day = 1;
else
   leap_day = 0;
end
if month <= 2
   leap_day = 0;
end

day_of_year = day + days(month) + leap_day;

fprintf('The date %2d/%2d/%4d is day of year %d.\n', ...
         month, day, year, day_of_year);

