Traditional Culture Encyclopedia - The 24 Solar Terms - I want to write a small program about the calendar in C language, but I don't know how to calculate the day of the week. I found a Kim Larsen formula on the Internet:

I want to write a small program about the calendar in C language, but I don't know how to calculate the day of the week. I found a Kim Larsen formula on the Internet:

On the Gregorian calendar, January 1st is Monday. Just calculate the number of days from this day to the Gregorian calendar year 1 month 1 day.

Another algorithm is that a period of 400 years, that is, 40 1, 1 month 1 day is also Monday, which can save many days.

A simpler algorithm is that a year is 365 days, and 364 days is a multiple of 7, that is, more than one day in a year, so that the days of leap years can be added, so that the first day of the year can be calculated. What day is today?

Year% = 400; //This is a cycle of 400 years.

Z= (year+year /4 years/100)% 7; //So you can keep fit.

for(m = 1; M< mouth; m++)

//This is the number of days in the year before this month, and finally add those days in this month.

{

if(I = 1 | | I = = 3 | | I = = 5 | | I = = 7 | | I = = 8 | | I = = 10 | | I = = 12)

d+= 3 1;

if(I = = 4 | | I = = 6 | | I = = 9 | | I = = 1 1)

d+= 30;

If (i==2)

If (year% 4 = = 0 & amp& amp year% 100 = = 0 | | year %400! =0)

d+=29

other

d+=28

}