/* Note:Your choice is C IDE */ #include "stdio.h" /*自定义函数说明*/ void screen(); /*系统主界面*/ void whatisit(); /*查询某年某月某日是星期几*/ void leapyear(); /*查询某年是否是闰年*/ void printyearday(); /*打印某年的全年日历*/ int IsLeapYear(int year); /*判断某年是否为闰年*/ int whatisita(int,int); /*计算当天是星期几*/ int everymonth(int,int); /*查询某月最大天数*/ void printmonth(int,int); /*打印某年某月月历*/ void printmonthday(); /*打印某年的某月最大天数*/ /***************************************************************/ /*定义指针数组*/ char *week[]={"Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"}; /***************************************************************/ /*主函数*/ void main() { screen(); } /***************************************************************/ /*万年历查询主界面(含部分功能)*/ void screen() { int n; while(1) { printf("ID:2013914122"); printf("万年历查询程序:\n"); printf("1.查询某年某月某日是星期几\n"); printf("2.查询某年是否是闰年 "); printf("3.打印某年的全年日历 "); printf("4.查询某月最大天数 "); printf("5.退出 "); 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-1+(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,sum; 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+i; n=(y-1+(y-1)/4-(y-1)/100+(y-1)/400+sum)&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(y,i); printmonth(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,i; 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+i; 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("%c",&yn);getchar(); if(yn=='y'||yn=='y') k=1; else k=0; } } /*打印月历*/ void printmonth(int value,int sum) { int n,i=0,j; char*x[7]={"Sunday","Monday","Tuesday","Wenesday","Tursday", "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++; } }