You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
int how(int A)//计算公元1月1号到输入年份之前的总天数的函数
{
int i,s=0,day;
for (i=1;i<=A-1;i++)
{
if (i%4==0 && i%100!=0 || i%400==0)
day=366;
else
day=365;
s=s+day;}
return s;
}
int where(int B,int C)//判断每月天数
{
int tian;
switch(C)
{ case 1: tian=31;break;
case 2:
if (B%4==0 && B%100!=0 || B%400==0)
tian=29;
else
tian=28;break;
case 3: tian=31;break;
case 4: tian=30;break;
case 5: tian=31;break;
case 6: tian=30;break;
case 7: tian=31;break;
case 8: tian=31;break;
case 9: tian=30;break;
case 10: tian=31;break;
case 11: tian=30;break;
case 12: tian=31;break;
}
return tian;
}
void why(int E)//判断输入日期是星期几
{
switch(E)
{
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;
case 7: printf("该日星期日\n");break;
}
}
void when(int F,int G)//判断日期是否为节日
{
if (F==1 && G==1 || F==5 && G==1 || F==10 && G==1|| F==3 && G==8 || F==6 && G==1 || F==9 && G==10)
printf ("当天为法定节日");
else
printf ("当天不是法定节日");
}
void main()
{ int year,d,j,Z,di,did,m,n,D,x,y,z,h,k,l,jian,Z1;//d代表1月1号是星期几Z代表总天数
printf ("欢迎来到日历查询系统!\n");
printf ("输入你所查寻日历的年份:");
scanf ("%d",&year);
Z=how(year);
for (j=1;j<=12;j++)
{
d=Z%7;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf (" %d月份\n",j);
printf ("sun mon tue wed thu fri sat\n");
if (d<6)
for (di=1;di<=d+1;di++)
printf(" ");
for (did=1;did<=where(year,j);did++)
{
printf ("%d",did); //注意空格和换行
if (did<10)
printf (" ");
else
printf (" ");
if (did==6-d || (did-6+d)%7==0 || did==where(year,j))
printf ("\n");
}
Z=Z+where(year,j); //计算下一个月的1月一号是星期几
}
printf ("输入所查日历的年月");
scanf ("%d%d",&m,&n);
Z=how(m);
for (j=1;j<=n-1;j++)
{
D=where(m,j);
Z=Z+D;
}
d=Z%7;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf (" %d月份\n",j);
printf ("sun mon tue wed thu fri sat\n");
if (d<6)
for (di=1;di<=d+1;di++)
printf(" ");
for (did=1;did<=where(year,j);did++)
{
printf ("%d",did);
if (did<10) //注意空格和换行
printf (" ");
else
printf (" ");
if (did==6-d || (did-6+d)%7==0 || did==where(year,j))
printf ("\n");
}
printf ("输入年月日");
scanf ("%d%d%d",&x,&y,&z);
Z=how(x);
for (j=1;j<=y-1;j++)
{
D=where(x,j);
Z=Z+D;
}
Z=Z+z;
printf ("输入当前年月日");
scanf ("%d%d%d",&h,&k,&l); //Z1为当前年月日的总天数
Z1=how(h);
for (j=1;j<=k-1;j++)
{
D=where(k,j);
Z1=Z1+D;
}
Z1=Z1+l;
jian=Z1-Z;
printf ("输入日期距今有%d天\n",jian);
d=Z%7;
why(d);
when(y,z);
}