#include<stdio.h>
void screen();
void whatisit();
void leapyear();
void printyearday();
int IsLeapYear(int);
int whatisita(int,int);
int everymonth(int,int);
void printmonth(int,int);
void printmonthday();
/******************************************************************/
char *week[]={"Sunday","Monday","Tuesday","Wednesday","Thurday","Friday","Saturday"};
void main()
{
int n;
while(1)
{
printf("万年历查询程序:\n");
printf("1.查询某年某月某日是星期几\n");
printf("2.查询某年是否是闰年\n");
printf("3.打印某年的全年的日历\n");
printf("4.查询某月的最大天数\n");
printf("5.退出\n");
printf("请输入要查询的选项:");
scanf("%d",&n);
switch(n)
{
case 1:whatisit();break;
case 2:leapyear();break;
case 3:printyearday();break;
case 4:printmonthday();break;
case 5:return;
default:printf("你输入错误,请按要求输入!!!\n");break;
}
}
}
void whatisit()
{
int y,m,d,s,k=1,sum,n,i;
char yn;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while(k)
{
printf("请依次输入年,月,日:\n");
scanf("%d,%d,%d",&y,&m,&d);
s=0;
for(i=1;i<m;i++)
s=s+a[i];
s=s+d;
if(IsLeapYear(y)&&m>2)s=s+1;
sum=s;
n=(y-2+(y+1)/4-(y-1)/100+(y-1)/400+sum)%7;//
printf("这天是%s\n",week[n]);
printf("是否继续查询(Y/N)?");
scanf("%c",&yn);getchar();
if(yn=='y'||yn=='y')k=1;
else k=0;
}
}
/**********************************************/
int IsLeapYear(int year)
{
return(year%4==0 &&year%100!=0)||(year%400==0);}
/************************************************/
void leapyear()
{int y,k=1;
char yn;
while(k)
{
printf("请输入要查询的年份:\n");
scanf("%d",&y);
if(IsLeapYear(y))
printf("是闰年!\n");
else
printf("不是闰年!\n");
printf("是否继续查询(Y/n)?");
scanf("%c",&yn);
getchar();
if(yn=='y'||yn=='Y')k=1;
else k=0;
}
}
/***********************************************************/
int whatisita(int y,int m)
{
int n,i;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},s=0;
for(i=1;i<m;i++)
s=s+a[i];
if(IsLeapYear(y)&&m>2)s=s+1;
n=(y-1+(y+1)/4-(y-1)/100+(y-1)/400+s+1)%7;
return n;
}
/******************************************************/
void printyearday()
{
int y,value,sum,i,k=1;char yn;
while(k)
{
printf("请输入查询日立的年份\n:");
scanf("%d",&y);
for(i=1;i<=12;i++)
{
printf("%d年%d月的信息:\n",y,i);
value=whatisita(y,i);
sum=everymonth(value,sum);
printf("\n");
}
printf("是否继续查询(Y/N)?");
scanf("%c",&yn);getchar();
if(yn=='y'||yn=='Y')k=1;
else k=0;
}
}
/******************************************************/
int everymonth(int year,int month)
{
int s;
static int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
s=a[month];
if(IsLeapYear(year)&&month==2)
s=s+1;
return s;
}
/***************************************************/
void printmonthday()
{
int y,m,value,k=1;char yn;
while(k)
{
printf("请输入查询的年份,月份\n:");
scanf("%d,%d",&y,&m);
value=everymonth(y,m);
printf("%d年%d月的最大天数为%d:\n",y,m,value);
printf("是否继续查询(Y/N)?");
scanf("%c",&yn);getchar();
if(yn=='y'||yn=='Y')k=1;
else k=0;
}
}
void printmmonth(int value,int sum)
{
int n,i=0,j;
char *x[7]={"Sunday","Monday","Tuesday","Wednesday","Thurday","Friday","Saturday"};//
for(j=0;j<7;j++)
{
printf("%s",x[j]);
}
printf("\n");
while(i<value){printf("");i++;}
for(n=1;n<7-value;n++)
printf("
%d",n);
while(n<sum)
{
if((n+value-1)%7==0)
printf("\n");
if(n/10>0)
printf("
%d",n);
else
printf("
%d",n);
n++;
}
}