《y年m月d日的前一天、后一天》由会员分享,可在线阅读,更多相关《y年m月d日的前一天、后一天(6页珍藏版)》请在金锄头文库上搜索。
1、#include enum MyEnum JAN=1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC;void yesterday(int *y, int *m, int *d)if (*d!=1)(*d)-;else /这个函数段是当日期为1 时,前一天day的选择:28 or 29 or 30or 31if (*m=1)(*y)-;*m = 12;else(*m)-;switch (*m)case FEB:if (*y%(*y%100?4:400=0)*d = 29;else*d = 28;break;case APR:case JUN:case S
2、EP:case NOV:*d = 30;break;default: *d = 31; /一直到这里,选择完毕。void tomorrow(int *y, int *m, int*d)int limit;switch (*m)case FEB:if (*y % (*y % 100 ? 4 : 400 = 0)limit = 29;elselimit = 28;break;case APR:case JUN:case SEP:case NOV:limit = 30;break;default:limit = 31;if (*d != 31)(*d)+;elseif (*m = 12)(*y)+;
3、*d = 1;*m = 1;else(*m)+;*d = 1;int shurupanduan(int year, int month, int day)int zhishi = 0;if (year0)if (month0&month0)int limit2;switch (month)case FEB:if (year%(year%100?4:400)=0)limit2 = 29;elselimit2 = 28;break;case APR:case JUN:case SEP:case NOV:limit2 = 30;break;default: limit2 = 31;if (day=l
4、imit2)zhishi = 1;return(zhishi);int main(void)int year, month, day,i;for (i = 0; i 6; i+)while (1)puts(请根据提示输入);puts(n);printf(请输入年、月、日用“空格”或者“回车”分开的标准日期:n);scanf_s(%d%d%d, if (shurupanduan(year,month,day)break;puts(请输入合乎规则的日期a _);puts(n);puts(waiting 3 _);puts(n);puts(waiting 2 _);puts(n);puts(wait
5、ing 1 _);puts(n);puts(n);puts(n);printf(您输入的日期为%d年%2d 月%2d日。n,year,month,day);puts(n);tomorrow(printf(您输入的日期的后面一天为%d年%2d月%2d 日。n, year, month, day); puts(n);yesterday(yesterday(printf(您输入的日期的前面一天为%d年%2d月%2d 日。n,year,month,day);puts(n);printf(# 剩余判断次数为:%d #n,(6 - i);puts(n);printf(贴心提示:年份键入9999 可提前退出判断程序 _ n);puts(n);if (year=9999)break;return(0);