/* File: thanks.c This program determines the date of Thanksgiving on any given year, after 1900. */ #include #include "genlib.h" #include "simpio.h" #include "calendar.h" main() { int year, month, i, first_thursday ; int start, this_month_days, turkey_day ; /* get year from user */ printf("year =? ") ; year = GetInteger() ; printf("\n") ; /* January 1900, starts on Monday */ start = 1 ; /* Calculate weekday of January 1 */ for (i = 1900; i < year ; i++) { start = AddDay(start, YearDays(i)) ; } /* Caluculate weekday of November 1 */ for (month = 1 ; month < 11 ; month++) { this_month_days = MonthDays(month, year) ; start = AddDay(start, this_month_days) ; } /* Calculate date of first Thursday */ if (start <= Thursday) { first_thursday = Thursday - start + 1 ; } else { first_thursday = Thursday - start + 1 + 7 ; } turkey_day = first_thursday + 21 ; printf("In %d, Thanksgiving is on November %d.\n", year, turkey_day) ; printf("\n November %d\n", year) ; printf(" Su M Tu W Th F Sa\n") ; PrintOneMonth(start, 30) ; }