Nextday

 1 //1.3.5.7.8.10.12都是31天的,2月份有28或29天,4.6.9.11只有30天
 2 //闰年2月则含有29天。非闰年2月含有28天
 3 #include <stdio.h>
 4 int montha(int year,int month)
 5 {
 6     if(month==2)    
 7     {
 8         if((year%4==0 && year%100!=0) || year%400==0)
 9             return(29);     //是闰年
10         else 
11             return(28);    //不是闰年
12     }
13     else if(month==4 || month==6 || month==9 ||  month==11)
14         return(30);
15     else 
16         return(31);
17 }
18 void NextData(int year,int month,int day)
19 {
20     if( month>12 || month<1)
21     {
22         printf("月输入有错!\n");
23     }
24     else
25     {
26         if(montha(year,month)<day)
27         {
28             printf("这一天不存在!");
29         }
30         else
31         {
32         day++;
33         if(day<=montha(year,month))
34             printf("year=%d month=%d day=%d",year,month,day);
35         else if(month+1<=12)
36         {
37             month++;
38             printf("year=%d month=%d day=%d",year,month,day);
39         }
40         else    
41         {
42             year++;
43             printf("year=%d month=%d day=%d",year,month,day);
44         }
45         }
46     }
47     
48 }
49 void main()
50 {
51     int year,month,day;
52     printf("请输入年 月 日\n");
53     scanf("%d %d %d",&year,&month,&day);
54     NextData(year,month,day);
55 }
56 /*测试用例
57 请输入年,月,日
58 2014 13 1
59 月输入有错!
60 Press any key to continue
61 
62 请输入年,月,日
63 2014 2 28
64 year=2014 month=3 day=1
65 Press any key to continue
66 
67 请输入年,月,日
68 2014 2 29
69 这一天不存在!
70 Press any key to continue
71 
72 请输入年,月,日
73 2014 12 32
74 这一天不存在!
75 Press any key to continue
76 
77 请输入年,月,日
78 2008 2 29
79 year=2008 month=3 day=1
80 Press any key to continue
81 
82 请输入年,月,日
83 2014 12 31
84 year=2015 month=1 day=1
85 Press any key to continue
86 
87 请输入年,月,日
88 2014 4 30
89 year=2014 month=5 day=1
90 Press any key to continue
91 */

 

转载于:https://www.cnblogs.com/lzr-rr/p/3571530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值