A formula, called Zeller\'s Congruence, may be used o the day of the week, given
ID: 3573063 • Letter: A
Question
A formula, called Zeller's Congruence, may be used o the day of the week, given the date (within a certain rang dates). The formula Is given below: f = 1 + ([2.6 - 0.2] + k + y + [y/4] + [c/4] - 2 c) modulo 7 where the square brackets denote the integer part, modulo 7 means the remainder when divided by 7, and m = the month number, with January and February taken as months 11, 12 of the preceding year, so March is then month 1, and December month 10; k = the day of the month; c = the century number; y = the year in the century; f = 1 means Sunday, 2 means Monday, etc For example, 23^rd August 1963 Is represented by m=6, k=23, c=19, y=63; 1^st January 1800 is represented by m=11, k=1, c=17, y=99. Write a function dayofweek(d) which takes the date in the form of a vector d=[dd mm yyyy] (e.g. [9 3 2001] for March 9, 2001 and returns the day of the week (in words) on which it falls. Test your program on some known dates, like today's date, or your birthday.Explanation / Answer
function day = dayofweek(d)
m = d(2);
y = mod(d(3),100);
c = floor(d(3)/100);
k = d(1);
f = floor(2.6*m-0.2)+k+y+floor(y/4)+floor(c/4)-2*c;
f = mod(f,7)+1;
if(f==1)
day = "Sunday";
end
if(f==2)
day = "Monday";
end
if(f==3)
day = "Tuesday";
end
if(f==4)
day = "Wednesday";
end
if(f==5)
day = "Thursday";
end
if(f==6)
day = "Friday";
end
if(f==7)
day = "Saturday";
end
end
dayofweek([23 6 1963])
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.