资源描述:
《c语言实现日历输出.cpp》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#includeintallday(intyear,intmonth){intk,leap,allday=0,preday=0;intAday=0;inttab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31},};leap=(year%4==0&&year%100!=0)
2、
3、year%400==0;for(k=1;k<=month-1;k++)Aday+=tab[leap][k];if(year>=2011){for(intj=2012;j<=
4、year;j++){if(j%400==0
5、
6、(j%4==0&&j%100!=0))preday+=366;elsepreday+=365;}allday=preday+Aday;}else{for(intj=2011;j>year;j--){if(j%400==0
7、
8、(j%4==0&&j%100!=0))preday+=366;elsepreday+=365;}allday=preday-Aday;}returnallday;}intmonthday(intyear,intmonth){intleap,D;inttab[2][13]={{0,31,28,31,30,31,30,31,3
9、1,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31},};leap=(year%4==0&&year%100!=0)
10、
11、year%400==0;D=tab[leap][month];returnD;}intmain(void){intyear,month,DAY,MD;inti,j,k;intPday;intcount=0;printf("请输入你想要查找的年月:");scanf("%d%d",&year,&month);DAY=allday(year,month);MD=monthday(year,month);if(year<2
12、011)Pday=DAY;printf("当月天数:%d该日是自公元元年一月一号起的第%d天",MD,DAY);printf("日一二三四五六");if(year>=2011){if((DAY==0)
13、
14、((DAY+1)%7==1)){for(i=1;i<=6;i++)printf("");printf("1");for(k=2;k<=MD;k++){if(k<=9)printf("%d",k);elseprintf("%d",k);count++;if(count%7==0)printf("");}}elseif((DAY+1)%7==2){for(j=1;j<=7;j
15、++)printf("%d",j);printf("");for(k=8;k<=MD;k++){if(k<=9)printf("%d",k);elseprintf("%d",k);count++;if(count%7==0)printf("");}}elseif((DAY+1)%7==3){printf("");for(j=1;j<=6;j++)printf("%d",j);printf("");for(k=7;k<=MD;k++){if(k<=9)printf("%d",k);elseprintf("%d",k);count++;if(count%7==0)printf("
16、");}}elseif((DAY+1)%7==4){for(i=1;i<=2;i++)printf("");for(j=1;j<=5;j++)printf("%d",j);printf("");for(k=6;k<=MD;k++){if(k<=9)printf("%d",k);elseprintf("%d",k);count++;if(count%7==0)printf("");}}elseif((DAY+1)%7==5){for(i=1;i<=3;i++)printf("");for(j=1;j<=4;j++)printf("%d",j);printf("");for(
17、k=5;k<=MD;k++){if(k<=9)printf("%d",k);elseprintf("%d",k);count++;if(count%7==0)printf("");}}elseif((DAY+1)%7==6){for(i=1;i<=4;i++)printf("");for(j=1;j<=3;j++)printf("%d",j);printf("");for(k=4;k<=MD;k++){if(k<=9)pri