a)

function res = monthsWithFriday13 ( year )
res = zeros (1 ,12) ;
	for month =1:12
	monthCalendar = getCalendar (year , month );
	% Fredag 13. kan kun vaere i 3. uken i en maaned
		if monthCalendar (3, 5) == 13
			res ( month ) = 1;	
		end
	end
end

 

b)

function year = maxFridays13()
year = 0;
top = 0;
pos = 1;
for i = 1900:2015
    temp = sum(monthsWithFriday13(i) );
    if temp > top
        year = i;
        top = temp;
        pos = 1;
    elseif temp == top
        pos = pos + 1;
        year(pos) = i;
    end
end
end
  • No labels