算法:使用基姆拉尔森计算公式
#include "stdio.h"
#include <stdlib.h>
void CaculateWeekDay(int y,int m, int d)
{
if(m==1||m==2) {
m+=12;
y--;
}
//使用基姆拉尔森计算公式
int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
switch(iWeek)
{
case 0: printf("星期一\n"); break;
case 1: printf("星期二\n"); break;
case 2: printf("星期三\n"); break;
case 3: printf("星期四\n"); break;
case 4: printf("星期五\n"); break;
case 5: printf("星期六\n"); break;
case 6: printf("星期日\n"); break;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int year=0,month=0,day=0;
printf("请输入日期:\n格式为:1900,1,1\n");
char temp = '1';
while (temp != '0')
{
scanf("%d,%d,%d",&year,&month,&day);
scanf("%c",&temp);
CaculateWeekDay(year,month,day);
printf("输入0退出,其他继续:");
scanf("%c",&temp);
}
system("pause");
return 0;
}
欢迎童鞋们访问并收藏我的博客小程序: