#include <stdio.h> #include <stdlib.h>
int statistic(int a) { int i,t=0; for(i=1;i<a;i++) if(i%4==0) { if(i%100!=0) t++; else if(i%400==0) t++; } return (t); }
int judge(int a) { int z; if(a%4!=0) z=0; else if(a%100!=0) z=1; else if(a%400==0) z=1; else z=0; return (z); }
void errorday() { printf("日输入错误\n\n"); system("PAUSE"); printf("\n"); }
void errormonth() { printf("月输入错误\n\n"); system("PAUSE"); printf("\n"); }
int main(int argc, char *argv[]) { int year,month,day,ruen_time,y_n,i; long days1,days2,days3,day_sum; static int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; do { printf("请输入年、月、日:\n"); scanf("%d %d %d",&year,&month,&day); y_n=judge(year); if(month>12) {errormonth();continue;} if(y_n==1) { if(month==2) {if(day>29) {errorday();continue;}} else if(day>m[month]) {errorday();continue;} } else if(day>m[month]) {errorday();continue;} ruen_time=statistic(year); days1=ruen_time+(year-1)*365; days2=0; for(i=0;i<month;i++) days2=days2+m[i]; if(month>2) days3=days2+y_n+day; else days3=days2+day; day_sum=days1+days3; switch(day_sum%7) { case 0:printf("%d年%d月%d日是星期日\n",year,month,day);break; case 1:printf("%d年%d月%d日是星期一\n",year,month,day);break; case 2:printf("%d年%d月%d日是星期二\n",year,month,day);break; case 3:printf("%d年%d月%d日是星期三\n",year,month,day);break; case 4:printf("%d年%d月%d日是星期四\n",year,month,day);break; case 5:printf("%d年%d月%d日是星期五\n",year,month,day);break; case 6:printf("%d年%d月%d日是星期六\n",year,month,day);break; default:break; } printf("\n"); system("PAUSE");printf("\n"); } while(1); }