disp('this program calculates the day of year given the'); disp('current date.'); month=input('Enter current month (1-12):'); day=input('Enter current day (1-31):'); year=input('Enter current 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 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 fprintf(' the date %2d/ %2d/ %4d is day of year %d.\n',month,day,year,day_of_year);\