disp('Calculates the day of the week given the current date');
month = input('Enter month 1-12: ');
day   = input('Enter day 1-31: ');
year  = input('Enter year yyyy: ');

leap_day = mod(year,400) == 0 || (mod(year,100) ~= 0 && mod(year,4) == 0);
leap_days = year-1 + floor(year/4) - floor(year/100) + floor(year/400) - leap_day;

days = [0 31 28+leap_day 31 30 31 30 31 31 30 31 30 31];
tot_days = day + sum(days(1:month)) + leap_days;
day_of_week = mod(tot_days, 7) + 1;
day_names = ['Sunday   ';'Monday   ';'Tuesday  ';'Wednesday';'Thursday ';'Friday   ';'Saturday '];

fprintf('The date %2d/%2d/%4d is %s.\n', month, day, year, day_names(day_of_week,:));

