Homework – Zeller’s Algorithm Pt2
Zeller’s algorithm computes the day of the week on which a givendate will fall (or fell). You are provided this algorithm inCANVAS. In this task, you must transform the provided solution to a“Defined Functionâ€
Function Name
zelleralg
Input Parameters | • month • day • year |
Return Values | The result from the algorithm. This is a number (0-6) thatcorresponds to the day of the week, where 0 represents Sunday, 1 isMonday, . . ., 6 is Saturday. |
Information collected from the input NONE (all user inputs fromMAIN script) command
Output to the screen NONE (all outputs printed from MAINscript)
On the main script, welcome the user, ask for his/her name, andDOB (date of birth). Then call the “defined function†and print-outa formatted output.
  Â
USER INPUT
USER INPUT
FORMATTED OUTPUT
Finally ask if the user if he/she wants to RERUN. If yes, loopyour code all-over. If not, just display a goodbye message.
]
(Below is the solution for the code. you just have to developthe user defined function and the rest of the instructions areabove. when finished it should look like the larger text)
clear
clc
% Welcome message
fprintf('Welcome. This program uses the Zeller''s algorithm tocompute\n')
fprintf('the day of the week for a given date. Outputs are givenas\n')
fprintf('numbers between 0 - 6:\n')
fprintf('(0) - Sun \t(1)- Mon \t(2)- Tue \t(3)- Wed \t(4)- Thu\t(5)- Fri')
fprintf('\t(6)- Sat\n')
fprintf('\nINPUT THE DATE:\n')
% Input section
Month = input('Month: ');
Day = input('Day: ');
Year = input('Year: ');
% A = 1 plus the remainder of (the month number plus 9) dividedby 12
A = 1+mod(Month+9,12);
% B = the day of the month
B = Day;
% C = the year of the century PLUS the ROUND DOWN from theequation: (0.09*Month-
0.27).
C = (mod( Year , 1000 ))+floor(0.09*Month-0.27);
%D = the century
D = floor( Year / 100 );
% Additional integers necessary for the calculation
W = floor((13*A-1)/5);
X = floor(C/4);
Y = floor(D/4);
Z = W+X+Y+B+C-2*D;
% R is the day of the week, where 0 represents Sunday, 1 isMonday, . . ., 6 is
Saturday
R = mod( Z, 7 );
fprintf('\nOUTPUT:\n')
fprintf('%d/%d/%d = %d\n', Month, Day, Year, R );