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.
145 lines
2.9 KiB
145 lines
2.9 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
int yearr(int year)
|
|
{
|
|
if (year%4==0&&year%100||year%400==0)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
int printfweek()
|
|
{
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n","周日","周一","周二","周三","周四","周五","周六");
|
|
}
|
|
int tian(int month,int year)
|
|
{
|
|
int day;
|
|
switch (month)
|
|
{
|
|
case 1:
|
|
case 3:
|
|
case 5:
|
|
case 7:
|
|
case 8:
|
|
case 10:
|
|
case 12:day=31;break;
|
|
case 4:
|
|
case 6:
|
|
case 9:
|
|
case 11:day=30;break;
|
|
case 2:{
|
|
if(year%400==0||(year%4==0&&year%100!=0))
|
|
day=29;
|
|
else
|
|
day=28;
|
|
}
|
|
break;
|
|
|
|
}
|
|
return day;
|
|
}
|
|
|
|
int prifirst(int month,int year)
|
|
{
|
|
int b;
|
|
if (month<3)
|
|
{
|
|
month=month+12;
|
|
year--;
|
|
}
|
|
b=(1+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
|
|
return b;
|
|
}
|
|
int prtmonth(int month)
|
|
{
|
|
switch (month)
|
|
{
|
|
case 1:printf("%26s\n","一月\n");break;
|
|
case 2:printf("%26s\n","二月\n");break;
|
|
case 3:printf("%26s\n","三月\n");break;
|
|
case 4:printf("%26s\n","四月\n");break;
|
|
case 5:printf("%26s\n","五月\n");break;
|
|
case 6:printf("%26s\n","六月\n");break;
|
|
case 7:printf("%26s\n","七月\n");break;
|
|
case 8:printf("%26s\n","八月\n");break;
|
|
case 9:printf("%26s\n","九月\n");break;
|
|
case 10:printf("%26s\n","十月\n");break;
|
|
case 11:printf("%26s\n","十一月\n");break;
|
|
case 12:printf("%26s\n","十二月\n");break;
|
|
}
|
|
}
|
|
int main()
|
|
{ int a;
|
|
int year,month,i,c,week;
|
|
printf("1:查询某一年日历\n2:查询某年某月有几天\n3:查询某日是一年中的第几天\n");
|
|
printf("请输入选项:\n") ;
|
|
scanf("%d",&a);
|
|
switch(a)
|
|
{
|
|
case 1:printf("年份\n:");
|
|
scanf("%d",&year);
|
|
for (month=1; month<=12; month++) {
|
|
c=1;
|
|
prtmonth(month);
|
|
printfweek();
|
|
week=prifirst(month,year);
|
|
if (week!=6)
|
|
for (i=0; i<=week; i++) {
|
|
printf("\t");
|
|
c++;
|
|
}
|
|
for (i=1; i<=tian(month,year); i++,c++)
|
|
{
|
|
printf("%d\t",i);
|
|
if (c%7==0)
|
|
{
|
|
printf("\n");
|
|
}
|
|
}
|
|
printf("\n");
|
|
}
|
|
return 0;
|
|
break;
|
|
case 2:int day;
|
|
printf("输入年月:\n");
|
|
scanf("%d%d",&year,&month);
|
|
day=tian(month,year);
|
|
printf("%d年%d月有%d天",year,month,day);
|
|
return 0;
|
|
break;
|
|
case 3:int flag=0,le,sum;
|
|
printf("输入年月日:\n");
|
|
scanf("%d%d%d",&year,&month,&day);
|
|
switch(month)
|
|
{ case 1:sum=0;break;
|
|
case 2:sum=31;break;
|
|
case 3:sum=59;break;
|
|
case 4:sum=90;break;
|
|
case 5:sum=120;break;
|
|
case 6:sum=151;break;
|
|
case 7:sum=181;break;
|
|
case 8:sum=212;break;
|
|
case 9:sum=243;break;
|
|
case 10:sum=273;break;
|
|
case 11:sum=304;break;
|
|
case 12:sum=334;break;
|
|
default:flag=1;
|
|
}
|
|
if(flag==0)
|
|
{
|
|
sum=sum+day;
|
|
if(year%400==0||(year%4==0&&year%100!=0))
|
|
le=1;
|
|
else
|
|
le=0;
|
|
if(le=1&&month>2)
|
|
sum++;
|
|
printf("%d月%d日是%d年的第%d天",month,day,year,sum);
|
|
return 0;
|
|
}
|
|
break;
|
|
}
|
|
return 0;
|
|
|
|
}
|