-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem19.c
50 lines (41 loc) · 816 Bytes
/
problem19.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2009, eagletmt
* Released under the MIT License <http://opensource.org/licenses/mit-license.php>
*/
#include <stdio.h>
static int days(int y, int m);
int main(void)
{
int year, wday = 0, sun = 0, mon;
for (year = 1901; year <= 2000; year++) {
for (mon = 1; mon <= 12; mon++) {
if (wday == 5) {
/* 1901-01-01 is Tuesday, so wday == 5 means Sunday */
sun++;
}
wday = (wday + days(year, mon))%7;
}
}
printf("%d\n", sun);
return 0;
}
int days(int y, int m)
{
switch (m) {
case 2:
if ((y%4 == 0 && y%100 != 0) || y%400 == 0) {
/* leap year */
return 29;
}
else {
return 28;
}
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 31;
}
}