year  = input('Enter year yyyy: ');
leap_day = mod(year,400) == 0 || (mod(year,100) ~= 0 && mod(year,4) == 0);
leap_days = year + 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];
offs = zeros(1,13);
offs(1) = mod(leap_days, 7);
for ii = 2:13
    offs(ii) = offs(ii-1)+days(ii);
end
offs = mod(offs, 7) + 1;
date = -offs + 2;
day_names = ['Su';'Mo';'Tu';'We';'Th';'Fr';'Sa'];
mon_names = ['Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'];
for months = 1:3:10
    for month = months:months+2
        fprintf('         %s           ', mon_names(month,:));
    end
    fprintf('\n');
    for month = months:months+2
        for day = 1:7
            fprintf(' %s', day_names(day,:)); 
        end
        fprintf('  ');
    end
    fprintf('\n');
    for week = 1:6
        for month = months:months+2
             for day = 1:7
                  if date(month) > 0 && date(month) <= days(month+1)
                      fprintf(' %2d', date(month));
                  else
                      fprintf('   ');
                  end
                  date(month) = date(month) + 1;
             end
             fprintf('  ');
        end
        fprintf('\n');
    end
    fprintf('\n');
end

