Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey i am doing a question where i had to code the day, month, and year for any g

ID: 3775134 • Letter: H

Question

Hey i am doing a question where i had to code the day, month, and year for any given input but i have to take in account of leap years. I have succesfully coded the day, month and year part but the part that i am having a hard time with is to code the leap years. I am suppose to code it from scratch while using NO SPECIAL FUNCTIONS. I was wondering if anybody could help me out! I understand the calculations on how to tell what year is a leap year but i just cant code it. Thanks for you're guys time.

I am working in MATLAB and it would be nice if somebody could comment back with MATLAB coding.   

Explanation / Answer

As per my understanding of the Question i have created the code.if still not satisfied please clear mention your code with your code.i will try to help you my best.

% variable used in this program

day = input('Enter the day(1-31) : ');

month = input('Enter the month(1-12) : ');

year = input('Enter the Year(yyyy) : ');

%Check for leap year

if mod(year,400) == 0

leap_flag = 1;

elseif mod(year,100) == 0

leap_flag = 0;

elseif mod(year,4) == 0

leap_flag = 1;

else

leap_flag = 0;

end

% Now determine the day of the year by adding today

day_of_year =day;

for i = 1:month-1

switch (i)

case {1,3,5,7,8,10,12}

day_of_year = day_of_year + 31;

case {4,6,9,11}

day_of_year = day_of_year + 30;

case 2

day_of_year = day_of_year + 28 + leap_flag;

end

end

fprintf('the date %2d/%2d/%4d is day of year %d. ', ...

month,day,year,day_of_year);