资源描述:
《c语言打印任意年份日历》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#includelongintf(intyear,intmonth){if(month<3)returnyear-1;elsereturnyear;}longintg(intmonth){if(month<3)returnmonth+13;elsereturnmonth+1;}longintn(intyear,intmonth,intday){return1461L*f(year,month)/4+153L*g(month)/5+day;}intw(intyear,intmonth,intday){return(int)((n(year,month,day)
2、%7-621049L%7+7)%7);}intdate[12][6][7];intday_tbl[][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};main(){intsw,leap,i,j,k,wd,day;intyear;chartitle[]="SUMMONTUEWEDTHUFRISAT";printf("Pleaseinputtheyearwhosecalendaryouwanttoknow:");scanf("%d%*c",&year);sw=w
3、(year,1,1);leap=year%4==0&&year%100
4、
5、year%400==0;for(i=0;i<12;i++)for(j=0;j<6;j++)for(k=0;k<7;k++)date[i][j][k]=0;for(i=0;i<12;i++)for(wd=0,day=1;day<=day_tbl[leap][i];day++){date[i][wd][sw]=day;sw=++sw%7;if(sw==0)wd++;}printf("
6、==================TheCalendarofYear%d==================
7、
8、"
9、,year);for(i=0;i<6;i++){for(wd=0,k=0;k<7;k++)wd+=date[i][5][k]+date[i+6][5][k];wd=wd?6:5;printf("%2d%s%2d%s
10、
11、",i+1,title,i+7,title);for(j=0;j12、("%4d",date[i+6][j][k]);elseprintf("");printf("
13、
14、");}}puts("==============================================================
15、");}