(1)代码
/* Note:Your choice is C IDE */ #include "stdio.h" void screen(); void printmonth(int,int); void leapyear(); void printyearday(); int IsLeapYear(int); int whatisita(int,int); int everymonth(int,int); void whatisit(); void printmonthday(); char*week[]={"Sun.","Mon.","Tue.","Wedn.","Thu.","Fri.","Sat."}; void main() { screen(); } void screen() { int n; while(1) { printf("标题:万年历查询程序:\n"); printf("1.查询某月的最大天数 "); printf("2.查询某年是否是闰年 "); printf("3.打印某年的全年日历 "); printf("4.查询某年某月某日是星期几\n"); printf("5.退出 "); printf("请输入要查询的选项:\n"); printf("(My ID number is:2013304132)\n"); scanf("%d",&n); switch(n) { case 1:printmonthday();break; case 2:leapyear();break; case 3:printyearday();break; case 4:whatisit();break; case 5:return; default:printf("您的输入有误,请重新按要求输入!\n"); break; } } } 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; 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;i2) 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("请输入查询日历的年份: "); 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 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;i2)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; printf("是否继续查询某年某月某日是星期几?(Y/N)"); scanf("%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]={"Sun.","Mon.","Tue.","Wedn.","Thu.", "Fri.","Sat."}; for(j=0;j<7;j++) { printf("%s",x[j]); } printf("\n"); while(i0) printf(" %d",n); else printf(" %d",n); n++; } }
(2)运行结果
(3)我的总结
a、随着信息时代的发展,我们的生活变得十分的快捷和美好。想查询任何一个年份的具体日期都可以得心应手,显得十分信息化和科技化。相信中国一定会在信息快速发展的时代变得更加繁荣昌盛。
b、通过这次程序设计,懂得编程要更加严谨和细心,否则钻死牛角尖都查不出问题。
c、由这次作业,对C语言编程有了更深入的了解。