Today's day of the week

Source: Internet
Author: User

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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.