UIT2024_Calendar/stu2024/网络2402朱治雨.c
2024-12-07 16:23:34 +08:00

52 lines
1.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
int main(){
int y,m,d,w,b,FOE=0;
char a[2]={'\0'};
while(FOE==0){
printf("万年历程序菜单:\n1 输出指定年份的日历\n2 查询指定日期的星期\n3 查询指定年份是否为闰年\n4 退出\n");//菜单
while(gets(a)){
if(a[0]=='4'&&a[1]=='\0'){ FOE=1; break; }//退出;
else if(a[0]=='1'&&a[1]=='\0'){
printf("想要查询的年份:"); scanf("%d",&y);
printf("日历的表现形式:\n1 单列输出\n2 双列输出\n"); scanf("%d",&b);
if(b==1) printf("111");
else if(b==2) printf("222");
getchar();
}//单双列;
else if(a[0]=='2'&&a[1]=='\0'){
printf("想查询的具体日期\n年:"); scanf("%d",&y);
printf("月:"); scanf("%d",&m);
printf("日:"); scanf("%d",&d);
if(m==1||m==2) y--,m+=12;
if(y<=1582&&m<=10&&d<=4){
if(m==1||m==2) y--,m+=12;
w=(d+2*m+3*(m+1)/5+y+y/4+5)%7+1;
}
else{
if(m==1||m==2) y--,m+=12;
w=(d+1+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
}
if(w==0) w=7;
printf("该日期是星期%d.\n按下Enter以继续",w);
getchar();
}//星期几;
else if(a[0]=='3'&&a[1]=='\0'){
printf("想查询的年份:"); scanf("%d",&y);
if((y%4==0&&y%100!=0)||y%400==0) printf("%d 是闰年.",y);
else printf("%d 不是闰年.按下Enter以继续\n",y);
getchar();
}//闰年查询;
if(a[0]!='1'&&a[0]!='2'&&a[0]!='3'&&a[0]!='4'&&a[0]!='\0'){ printf("输入错误!请重新输入:\n");a[0]='\0';a[1]='\0';continue;}
else if((a[0]=='1'||a[0]=='2'||a[0]=='3'||a[0]=='4')&&a[1]!='\0'){ printf("输入错误!请重新输入:\n");a[0]='\0';a[1]='\0';continue;}
FOE=0;
if(a[0]!='\0') getchar();
system("cls");
a[0]='\0';a[1]='\0';
break;
//防报错(部分);
}
}
}