#include /* * 基姆拉尔森计算公式 * W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 */ int week(int y, int m, int d) { if (m < 3) { m += 12; y--; } int w = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; return w; } int main() { printf("%d ", week(2015, 4, 16)); // => 3 星期四 printf("%d ", week(1989, 2, 3)); // => 4 星期五 return 0; }