-
-
Save 6david9/71e989b0beb48f8bc52e to your computer and use it in GitHub Desktop.
计算万年历星期(基姆拉尔森)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
* 基姆拉尔森计算公式 | |
* 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\n", week(2015, 4, 16)); // => 3 星期四 | |
printf("%d\n", week(1989, 2, 3)); // => 4 星期五 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment