资源描述:
《用c语言编写万年历》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include//假设今天是2013年12月22号,是星期天,根据这个日期计算日历中的某天距离今天有多少天,且输入的日期为星期几!查表得1800年1月1日为星期三。inti,j,k,a,b,c,w=0;//i,j,k分别代表全局变量的年月日。inty(){intp,h=0,inleap=0,leap=0,sum=0,count1,count2,leap1;scanf("%d",&i);if(i>2100
2、
3、i<1800)printf("输入的年份不合法,或者不在程序运算的范围内");else{printf("%d年的年历为:",i);for(j=1;j<=12;
4、j++){{for(a=1800;a<=i;a++){if((a%4==0&&a%100!=0)
5、
6、(a%400==0))leap++;elseinleap++;}count1=leap*366;count2=inleap*365;switch(j){case1:sum=0;break;case2:sum=31;break;case3:sum=59;break;case4:sum=90;break;case5:sum=120;break;case6:sum=151;break;case7:sum=181;break;case8:sum=212;break;case9:sum=243;b
7、reak;case10:sum=273;break;case11:sum=304;break;case12:sum=334;break;}sum=sum+count1+count2;{if(i%400==0
8、
9、(i%4==0&&i%100!=0))leap1=1;//如果不是闰年则直接执行elseleap1=0;if(leap1==1&&j>2)//如果是闰年并且月份大于2,总天数应该加一天sum++;}h=(sum+2)%7;}if((i%4==0&&i%100!=0)
10、
11、(i%400==0)){switch(j){case1:case3:case5:case7:case8:case
12、10:case12:printf("tt%d月",j);printf("%4s%4s%4s%4s%4s%4s%4s","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p13、n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p14、);if((c+h)%7==0)printf("");}printf("");}}else{switch(j){case1:case3:case5:case7:case8:case10:case12:printf("tt%d月",j);printf("%4s%4s%4s%4s%4s%4s%4s","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p15、intf("");break;case4:case6:case9:case11:printf("tt%d月",j);printf("%4s%4s%4s%4s%4s%4s%4s","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p