/* Returns true if the given year is a leap year */
static bool IsLeapYear(int year)
{
if ((year % 400) == 0)
return true;
if ((year % 100) == 0)
return false;
if ((year % 4) == 0)
return true;
return false;
}
2.6. What day of the week was 2 August 1953?
--------------------------------------------
To calculate the day on which a particular date falls, the following
algorithm may be used (the divisions are integer divisions, in which
remainders are discarded):
a = (14 - month) / 12
y = year - a
m = month + 12*a - 2
For Julian calendar: d = (5 + day + y + y/4 + (31*m)/12) mod 7
For Gregorian calendar: d = (day + y + y/4 - y/100 + y/400 + (31*m)/12) mod 7
The value of d is 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, etc.
Example: On what day of the week was the author born?
My birthday is 2 August 1953 (Gregorian, of course).
a = (14 - 8) / 12 = 0
y = 1953 - 0 = 1953
m = 8 + 12*0 - 2 = 6
d = (2 + 1953 + 1953/4 - 1953/100 + 1953/400 + (31*6)/12) mod 7
= (2 + 1953 + 488 - 19 + 4 + 15 ) mod 7
= 2443 mod 7
= 0
I was born on a Sunday.
Прочтите Календарь FAQ для получения дополнительной информации.