I am trying to find the fourth Thursday of November (thanksgiving day) of any user inputted year. I used the following function to find the day of December 31'st of the previous year of user inputted year.
int yr;
int lastDayofDecember;
scanf("%i",&yr);
lastDayofDecember = (((yr-1)*365)+((yr-1)/4)-((yr-1)/100)+((yr-1)/400))%7;
where, lastDayofDecember = 0 : Sunday, 1 : Monday,......6:Saturday;
Now for year 2016
, the last day was a Saturday i.e lastDayofDecember = 6
, I added 5
to it to find the first thursday of January and added 304
to it to find the first Thursday of November (January 1 - November 1 is 304 days for non-leap year) to which I added 21 to find the fourth thursday of November, but now I am confused about what to do next. I can not use loops
int txDay = 5 + 304 + 21;