Skip to content

Instantly share code, notes, and snippets.

@6david9
Created March 9, 2015 16:48
Show Gist options
  • Save 6david9/71e989b0beb48f8bc52e to your computer and use it in GitHub Desktop.
Save 6david9/71e989b0beb48f8bc52e to your computer and use it in GitHub Desktop.
计算万年历星期(基姆拉尔森)
#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