// known 1999.12.31 is Friday// according to the date of year, the Judgment 20XX xx month xx days is the day of the week#include"stdio.h"unsignedintyear;unsignedintmonth;unsignedintDay ;//===============================================================================//determine if a leap year//===============================================================================//the number of years in A.D. can be divisible by four and not divisible by 100, which is a leap year; //divisible by 100 can also be divisible by 400 for a leap year;//divisible by 100 and not divisible by 400 to common year;CharWhether_leapyear (unsignedinty) { return(y%4==0&& y% -!=0) || (y% -==0);}//----------------------------------//Verify the maximum number of days per month//----------------------------------UnsignedintMax_valid_day (unsignedintmonthtemp) {unsignedintMaxday; Switch(monthtemp) {//1.3.5.7.8.10.12 Month 31 days Case 1: Case 3: Case 5: Case 7: Case 8: Case Ten: Case A: Maxday= to; Break; //4.6.9.11 Month 30 days Case 4: Case 6: Case 9: Case One: Maxday= -; Break; Case 2: if(Whether_leapyear (year)) Maxday= in;//leap year February 29 days ElseMaxday= -;//common year February 28 days Break; } returnMaxday;}//----------------------------------------//Day of the week starting from 2000.1.1//function does not find the total number of days, and then the day of the week//because the total number of days may exceed the range of uint//----------------------------------------UnsignedintGet_weekday (unsignedintryear,unsignedintrmonth,unsignedintrday) {unsignedinti; unsignedintD; unsignedintw=5;//known 1999.12.31 is Friday//calculated starting from 2000.1.1 (current year i-1) year 12.31 is the day of the Week (W) for(i= -; i<ryear; i++) {D= Whether_leapyear (i)?366:365; W= (w + d)%7; } //calculates the day ordinal of the year that is currently set for(d=0, i=1; i<rmonth; i++) d+=Max_valid_day (i); D+=Rday; //calculates the current "year/month/day" according to W and D is the days of the week//The return value is: 0-1-2-3-4-5-6//Correspondence Week: Day 123456 return((w + d)%7);}voidMainvoid){ while(1) {printf ("Please enter the day of the month \ n"); scanf ("%d%d%d",&year,&month,&Day ); printf ("%d years%d months%d days is week", Year,month,day); printf ("%d \ n", Get_weekday (Year,month,day)); printf ("---------------------------------------\ n"); }}
According to the date of year, the Judgment 20XX xx month xx days is the day of the week