#include #include #include int Y(int Z) //距公元元年元月1日的天数 { int i,s=0,day; for(i=1;i<=Z-1;i++) { if(i%4==0&&i%100!=0||i%400==0) day=366; else day=365; s=s+day; } return s; } int month(int X,int C) //月份(分平闰年) { int V; switch(C) { case 1: V=31;break; case 2: if(V%4==0&&V%100!=0||V%400==0) V=29; else V=28; break; case 3: V=31;break; case 4: V=30;break; case 5: V=31;break; case 6: V=30;break; case 7: V=31;break; case 8: V=31;break; case 9: V=30;break; case 10: V=31;break; case 11: V=30;break; case 12: V=31;break; } return V; } int weekday(int V) //判断是星期几 { switch(V) { case 1: printf("\n当天是星期一\n");printf("\a");break; case 2: printf("\n当天是星期二\n");printf("\a");break; case 3: printf("\n当天是星期三\n");printf("\a");break; case 4: printf("\n当天是星期四\n");printf("\a");break; case 5: printf("\n当天是星期五\n");printf("\a");break; case 6: printf("\n当天是星期六\n");printf("\a");break; case 7: printf("\n当天是星期日\n");printf("\a");break; } } int holiday(int F,int G) //判断该天是否为法定节日 { if(F==1&&G==1) printf("\n当天为元旦"); else if(F==5&&G==1) printf("\n当天为劳动节"); else if(F==6&&G==1) printf("\n当天为儿童节"); else if(F==8&&G==1) printf("\n当天为建军节"); else if(F==10&&G==1) printf("\n当天为国庆节"); else printf("\n当天不是法定节日"); } using namespace std; int main(void) { int year,d,j,Z,ds,dd,m,n,D,x,y,z,h,k,l,B,Z1; printf("\n输入你所查寻日历的年份:"); scanf("%d",&year); if((year%4==0&&year%100!=0)||year%400==0) { printf("\n 该年是闰年"); printf("\a"); } else { printf("\n 该年是平年"); printf("\a"); } Z=Y(year); for(j=1;j<=12;j++) { d=Z%7; printf("\n-----------------------------\n"); printf(" %d月份\n",j); printf("SUN MON TUE WED THU FRI SAT\n"); if(d<6) for(ds=1;ds<=d+1;ds++) printf(" "); for(dd=1;dd<=month(year,j);dd++) { printf ("%d",dd); if (dd<10) printf(" "); else printf(" "); if (dd==6-d||(dd-6+d)%7==0||dd==month(year,j)) printf("\n"); } Z=Z+month(year,j); } printf("\n输入所查日历的年月:"); scanf("%d%d",&m,&n); Z=Y(m); for(j=1;j<=n-1;j++) { D=month(m,j); Z=Z+D; } d=Z%7; printf("\n-----------------------------\n"); printf(" %d月份\n",j); printf("SUN MON TUE WED THU FRI SAT\n"); if(d<6) for(ds=1;ds<=d+1;ds++) printf(" "); for(dd=1;dd<=month(year,j);dd++) { printf("%d",dd); if(dd<10) printf(" "); else printf(" "); if(dd==6-d||(dd-6+d)%7==0||dd==month(year,j)) printf("\n"); } printf("\n输入年月日:"); scanf("%d%d%d",&x,&y,&z); Z=Y(x); for(j=1;j<=y-1;j++) { D=month(x,j); Z=Z+D; } Z=Z+z; printf("\n输入当前年月日:"); scanf("%d%d%d",&h,&k,&l); Z1=Y(h); for(j=1;j<=k-1;j++) { D=month(k,j); Z1=Z1+D; } Z1=Z1+l; B=Z1-Z; printf("\n输入日期距今有%d天\n",B); d=Z%7; weekday(d); holiday(y,z); }