Today's day of the week: For a given date, determine the day of the week, starting from January 1, January 1.
# Include <iostream> # include <cstdio> using namespace STD; // determines the number of void Week (INT y, int M, int D) of a week for a given date) {// E represents the number of days int T, E; Switch (m) {Case 1: E = D; break; Case 2: E = 31 + D; break; Case 3: E = 59 + D; break; Case 4: E = 90 + D; break; Case 5: E = 120 + D; break; Case 6: E = 151 + D; break; Case 7: E = 181 + D; break; case 8: E = 212 + D; break; Case 9: E = 243 + D; break; case 10: E = 273 + D; break; Case 11: E = 304 + D; brea K; Case 12: E = 334 + D; break;} // if it is a runner-up year, add 1 If (Y % 4 = 0 & Y % 100! = 0) | (Y % 400 = 0) if (M> 2) ++ E; -- y; /*** T = 365 * Y + Y/4-y/100 + Y/400 + E; ** t = (52*7 + 1) * Y + Y/4-y/100 + Y/400 + E; ** y/4-y/100 + Y/400 represents the number of days from the first year to the leap year of this year. ** T % = 7; similar to T = Y + Y/4-y/100 + Y/400 + E; t = T % 7; so: * // similar to a small knowledge: last year, today is one day less than today. t = Y + Y/4-y/100 + Y/400 + E; t = T % 7; if (t = 1) printf ("Monday \ n"); else if (t = 2) printf ("Tuesday \ n "); else if (t = 3) printf ("Wednesday \ n"); else if (t = 4) printf ("Thursday \ n "); else if (t = 5) printf ("Friday \ n"); else if (t = 6) printf ("Saturday \ n "); else printf ("Sunday \ n");} int main () {// from the output result, we can see that week (, 15) is missing in the week. Week, 15); Return 0 ;}