您的位置:首页 > 其它

使用蔡勒(Zeller)公式计算任意一天星期几

2013-09-05 15:22 357 查看
推理过程见
Zeller:

struct date
{
int year;
short month,day;
};

int zeller( struct date t )
{
if (t.month<3)
{
t.year = t.year - 1;
t.month = t.month + 12;
}
int c = t.year / 100;
int y = t.year % 100;
int ans = ( c/4 - 2*c + y + y/4 + (26*(t.month+1))/10 + t.day - 1 ) % 7;

if (ans>0) return ans;
else return ans+7;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: