Formula
Caille (Zeller) formula, is a calculation of the week formula, casually to a date, you can use this formula to calculate the day of the week.
To calculate the date on or before October 4, 1582, the formula is the example of September 3, 1582: After September 3, 1582: W = (d + 2*m+3* (m+1)/5+y+y/4-y/100+y/400)%7; September 3, 1582 before: W = (d+2*m+3* (m+1)/5+y+y/4+5)% 7;
NoteIn the Year 1, February as the last year of 13, 1 April to calculate
Symbolic MeaningW: Week; W 7 modulo: 0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday C: Century (the first two digits of the year) Y: Year (the last two digits) m: month (M is greater than or equal to 3, less than or equal to 14, in the Caille formula, 1 February should be considered as the last year of 13, 1 April to calculate, such as January 1, 2003 to be considered as the 2002 1 March 1 to calculate) d: Day [] represents rounding, that is, as long as the integer part. The following is the day of the 100 anniversary of the founding of the People's Republic of China (October 1, 2049), the process is as follows: W=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1 =49+[49/4]+[20/4]-2x20+[26x (10+1)/10]+1-1 =49+[12.25]+5-40+[28.6] =49+12+5-40+28 = 54 (divided by 7 + 5) that is October 1, 2049 (100 Anniversary National Day) is Friday. Another example is the calculation of April 4, 2006, the process is as follows: W=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1 =6+[6/4]+[20/4]-2*20+[26* (4+1)/10]+4-1 =-12 (divided by 7 more than 5, note the negative Take the modulo operation! Should actually be Tuesday instead of Friday) w= ( -12%7+7)%7=2;
Scope of applicationHowever, the Caille formula is only suitable for 1582 (China's Ming Dynasty Wanli 10 years) after October 15. Pope Gregory 13 organized a group of astronomers in 1582 to revise the Julian calendar according to the data calculated by Copernicus heliocentric. 10 days between 14th and October 5, 1582 will be revoked, following October 4 for October 15. Later, the new calendar was called the Gregorian calendar, which is the universal calendar of today's world, referred to as Gregorian calendar.
Code
1#include <stdio.h>2 3 intMain ()4 {5 intYear , month, day, C, Y, W;6 Charb[7][Ten] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };7scanf"%d%d%d", &year, &month, &Day );8 if(Month <3)9 {Tenyear--; OneMonth + = A; A } -c = year/ -; -y = year% -; theW = (c/4) -2* C + (y + y/4) + ( -* (Month +1) /5) + Day-1; -w = (w%7+7) %7; - puts (b[w]); - return 0; +}
How to calculate the day of the week?