#include<stdio.h>
#include<windows.h>
int menu()
{
char ch;
int x;
system("cls");
printf("请选择相应的菜单:\n");
printf("***********************************\n");
printf("查询某年某月某日是星期几,输入1回车:\n");
printf("查询某年是否是闰年,输入2回车:\n");
printf("打印某年的全年日历,输入3回车:\n");
printf("退出,输入0回车:\n");
printf("***********************************\n");
scanf("%d",&x);
if(x==0)
{
printf("确认退出? Y/N ");
ch=getchar();
scanf("%c",&ch);
if(ch=='Y')
exit(0);
else
main();
}
return x;
}
int judge_week(year,mon,day)
{
int sum,i,flag=0;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
sum=30*(mon-1)+day;
for(i=1;i<=mon-1;i++)
{
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
sum+=1;
if(i==2)
{
if(flag==1)
sum-=1;
if(flag==0)
sum-=2;
}
}
return sum;
}
look_week()
{
int year,mon,day,C,S,k;
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要查询的年月日\nyear month day\n");
scanf("%d %d %d",&year,&mon,&day);
if(year<0 || mon<0 || mon>12 || day<0 || day>31)
{
system("cls");
printf("输入的年月日不正确,请重新输入!");
Sleep(3000);
look_week();
}
C=judge_week(year,mon,day);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
system("cls");
printf("\n%d年%d月%d日是星期%s.\n\n",year,mon,day,week[k]);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_week();
else
main();
}
look_runnian()
{
int flag=0,year;
char ch;
system("cls");
printf("请输入要查询的年份: ");
scanf("%d",&year);
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
system("cls");
if(flag==1)
printf("%d是润年\n",year);
else
printf("%d不是润年\n",year);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_runnian();
else
main();
}
print_calendar()
{
int i,j=0,k,C,S,flag=0,m,year,mon,d[31];
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要打印日历的年、月:\nyear month\n");
scanf("%d %d",&year,&mon);
C=judge_week(year,mon,1);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
if(mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12)
m=31;
else if(mon==2)
{
if(flag==1)
m=29;
if(flag==0)
m=28;
}
else
m=30;
for(i=1;i<=m;i++)
d[j++]=i;
system("cls");
printf("%d年%d月的日历如下:\n\n",year,mon);
for(i=0;i<7;i++)
printf("%s\t",week[i]);
putchar(10);
for(i=0;i<k;i++)
printf("\t");
j=k;
for(i=0;i<m;i++)
{
printf("%d\t",d[i]);
j++;
if(j%7==0)
putchar(10);
}
printf("\n\n是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
print_calendar();
else
main();
}
main()
{
int a;
a=menu();
switch(a)
{
case 1:look_week();break;
case 2:look_runnian();break;
case 3:print_calendar();break;
default:
{
printf("输入有误,请重新选择相应的菜单:\n");
Sleep(3000);
main();
}
}
}
追问编译器报错了