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

Write a program to create a calendar for a year. The program reads the year from

ID: 3639896 • Letter: W

Question

Write a program to create a calendar for a year. The program reads the year from the keyboard. It then calculates which day of the week (SUN through SAT) is the first day of the year and prints the calendar for that year. After printing the year the program should ask if the user wants to continue. If the answer is yes, it will print the calendar for another year until the user is done. Below is an example of how a one month should look like when it is printed.

JANUARY 2000

SUN MON TUE WED THU FRI SAT
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Hint1: To print the correct calendar for the requested year, you must first find which day of the week is the first day of that year. This can be done with the following formula.

DAY =

DAY=0: SUN
DAY=1: MON
DAY=2: TUE
DAY=3: WED
DAY=4: THU
DAY=5: FRI
DAY=6: SAT

Hint2: You must also calculate leap years. The formula for calculating leap years is:

(!(year % 4) && (year % 100)) || !(year % 400)

Explanation / Answer

#include int main() { int month, day, year, prevyear, numdays; printf("Please enter a date for month-day-year: "); scanf("%d-%d-%d", &month, &day, &year); prevyear = ((year - 1) * 365 + ((year - 1)/4) - ((year - 1)/100) + ((year - 1)/400)) % 7; numdays = 0; switch(month) { case 12: numdays += 30; break; case 11: numdays += 31; break; case 10: numdays += 30; break; case 9: numdays += 31; break; case 8: numdays += 31; break; case 7: numdays += 30; break; case 6: numdays += 31; break; case 5: numdays += 30; break; case 4: numdays += 31; break; case 3: if ((!(year % 4) && (year % 100)) || ! (year % 400)) numdays += 29; else numdays += 28; break; case 2: numdays += 31; break; } switch(day) { case 6: printf("The day was Saturday"); break; case 5: printf("The day was Friday"); break; case 4: printf("The day was Thursday"); break; case 3: printf("The day was Wedensday"); break; case 2: printf("The day was Tuesday"); break; case 1: printf("The day was Monday"); break; case 0: printf("The day was Sunday"); break; } return(0); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote