nextdate函数的代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includestdlib.hvoidmain(){intyear,month,day;voidnextdate(int,int,int);printf(请输入年份(范围在1912-2050之间):);scanf(%d,&year);printf(请输入月份(范围在1-12之间):);scanf(%d,&month);printf(请输入日期(范围在1-31之间):);scanf(%d,&day);printf(%d年%d月%d日的下一天是:,year,month,day);nextdate(year,month,day);}voidnextdate(intyear,intmonth,intday){intleap(int);switch(month){case1:case3:case5:case7:case8:case10:if(day=1&&day31)day=day+1;elseif(day==31){day=1;month=month+1;}elseprintf(输入数据错误!\n);break;case12:if(day=1&&day31)day=day+1;elseif(day==31){day=1;month=1;year=year+1;}else{printf(输入数据错误!\n);exit(0);}break;case4:case6:case9:case11:if(day=1&&day30)day=day+1;elseif(day==30){day=1;month=month+1;}else{printf(输入数据错误!\n);exit(0);}break;case2:if(day=1&&day28)day=day+1;elseif(!leap(year)&&day==28){day=1;month=month+1;}elseif(leap(year)&&day==28)day=day+1;elseif(leap(year)&&day==29){day=1;month=month+1;}else{printf(输入数据错误!\n);exit(0);}}printf(%d年%d月%d日\n,year,month,day);}intleap(intyy){return(yy%400==0||(yy%4==0&&yy%100!=0));}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功