|
|
@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
#include<math.h>
|
|
|
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#include<time.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 每月天数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int month_day(int year,int month)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(month)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
|
|
|
|
return 31;break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
|
|
|
|
return 30;break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if((year%4==0)&&(year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 29;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 28;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 年历
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void year_calendar(int year)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int month,days,weekday,sum_day;
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
year;
|
|
|
|
|
|
|
|
printf("请输入要查询的年份:");
|
|
|
|
|
|
|
|
scanf("%d",&year);
|
|
|
|
|
|
|
|
for(i=1;i<year;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((year%4==0)&&(year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
sum_day+=366;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sum_day+=365;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(month=1;month<=12;month++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n--------%d/%d--------\n",year,month);
|
|
|
|
|
|
|
|
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
weekday=sum_day%7;
|
|
|
|
|
|
|
|
while(i<=weekday) //开始位置前都是空格
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\t");
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(j<=month_day(year,month))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
weekday=sum_day%7;
|
|
|
|
|
|
|
|
if (weekday==6)
|
|
|
|
|
|
|
|
printf("%d\n",j);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf("%d\t",j);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(j==month_day(year,month))
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
sum_day++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 月历
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void month_calendar(int year,int month)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int sum_day=0,weekday,i,j,k;
|
|
|
|
|
|
|
|
printf("请输入要查询的年/月:");
|
|
|
|
|
|
|
|
scanf("%d/%d",&year,&month);
|
|
|
|
|
|
|
|
for(i=1;i<year;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((year%4==0)&&(year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
sum_day+=366;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sum_day+=365;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k=1;k<month;k++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sum_day+=month_day(year,month);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n\t--------%d/%d--------\n",year,month);
|
|
|
|
|
|
|
|
printf("\tSUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n");
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
weekday=sum_day%7;
|
|
|
|
|
|
|
|
while(i<=weekday) //开始位置前都是空格
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\t");
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(j<=month_day(year,month))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
weekday=sum_day%7;
|
|
|
|
|
|
|
|
if (weekday==6)
|
|
|
|
|
|
|
|
printf("%d\n",j);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf("%d\t",j);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(j==month_day(year,month))
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
sum_day++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 距今多少天
|
|
|
|
|
|
|
|
void Time(int year,int month,int day)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time_t t;//将t声明为时间变量
|
|
|
|
|
|
|
|
struct tm *p;//struct tm是一个结构体,声明一个结构体指针
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
|
|
|
|
p=localtime(&t);//获得当前时间
|
|
|
|
|
|
|
|
int now_year,now_month,now_day;
|
|
|
|
|
|
|
|
now_year=1900+p->tm_year;
|
|
|
|
|
|
|
|
now_month=1+p->tm_mon;
|
|
|
|
|
|
|
|
now_day=p->tm_mday;
|
|
|
|
|
|
|
|
printf("当前日期是:%d/%d/%d\n",now_year,now_month,now_day);
|
|
|
|
|
|
|
|
//输入日期的总天数
|
|
|
|
|
|
|
|
int i,k,sum_day;
|
|
|
|
|
|
|
|
printf("请输入要查询的年/月/日:");
|
|
|
|
|
|
|
|
scanf("%d/%d/%d",&year,&month,&day);
|
|
|
|
|
|
|
|
for(i=1;i<year;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((year%4==0)&&(year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
sum_day+=366;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sum_day+=365;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k=1;k<month;k++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sum_day+=month_day(year,month);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sum_day+=day;
|
|
|
|
|
|
|
|
//当前总日期
|
|
|
|
|
|
|
|
int j,sum_nowday;
|
|
|
|
|
|
|
|
for(j=1;j<now_year;j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((now_year%4==0)&&(now_year%100!=0)||(now_year%400==0))
|
|
|
|
|
|
|
|
sum_nowday+=366;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sum_nowday+=365;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k=1;k<now_month;k++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sum_nowday+=month_day(now_year,now_month);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sum_nowday+=now_day;
|
|
|
|
|
|
|
|
//相减得差值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(sum_day>sum_nowday)
|
|
|
|
|
|
|
|
printf("\n输入日期与当前日期相差%d天",sum_day-sum_nowday);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf("\n输入日期与当前日期相差%d天",sum_nowday-sum_day);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//日期查询
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rq(int year,int month,int day)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("请输入要查询的年/月/日:");
|
|
|
|
|
|
|
|
int sum_day,i,k,weekday;
|
|
|
|
|
|
|
|
scanf("%d/%d/%d",&year,&month,&day);
|
|
|
|
|
|
|
|
for(i=1;i<year;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((year%4==0)&&(year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
sum_day+=366;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sum_day+=365;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k=1;k<month;k++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sum_day+=month_day(year,month);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sum_day+=day;
|
|
|
|
|
|
|
|
weekday=sum_day%7;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
switch(weekday)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期日");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期一");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期二");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期三");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期四");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期五");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("星期六");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
|
|
|
if(month==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("元旦");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==14)
|
|
|
|
|
|
|
|
printf("情人节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(day)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 8:printf("妇女节");break;
|
|
|
|
|
|
|
|
case 12:printf("植树节");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==4)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("愚人节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(day)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:printf("劳动节");break;
|
|
|
|
|
|
|
|
case 4:printf("青年节");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==6)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("儿童节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==7)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("建党节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==8)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("建军节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==9)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==10)
|
|
|
|
|
|
|
|
printf("教师节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==10)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==1)
|
|
|
|
|
|
|
|
printf("国庆节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(month==11)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(day==25)
|
|
|
|
|
|
|
|
printf("圣诞节");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n-------------------选择服务-------------------\n\n");
|
|
|
|
|
|
|
|
printf(" 1.年历显示\n");
|
|
|
|
|
|
|
|
printf(" 2.月历显示\n");
|
|
|
|
|
|
|
|
printf(" 3.距今多少天\n");
|
|
|
|
|
|
|
|
printf(" 4.日期查询\n");
|
|
|
|
|
|
|
|
printf(" 5.退出\n");
|
|
|
|
|
|
|
|
printf("\n-------------------选择服务-------------------\n") ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int n,year,month,day;
|
|
|
|
|
|
|
|
printf("请选择服务:");
|
|
|
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
year_calendar(year);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
month_calendar(year,month);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Time(year,month,day);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rq(year,month,day);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|