首页 > 代码库 > 判断某年某月的天数

判断某年某月的天数

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 //判断指定的某年某月有多少天
 4 void main()
 5 {
 6     int year,month;
 7     int leap,days;
 8     printf("please input a year ,month\n");
 9     scanf("%d-%d",&year,&month);
10     if((year%4==0)&&(year%100!=0)||((year%4==0)&&(year%100==0)&&(year%400==0)))
11        leap = 1;
12     else
13         leap = 0;
14     switch(month)
15     {
16       case 1:
17       case 3:
18       case 5:
19       case 7:
20       case 8:
21       case 10:
22       case 12:  days = 31;break;
23       case 4:
24       case 6:
25       case 9:
26       case 11:  days = 30;break;
27       case 2:  days = 28 + leap;break;
28       default :days = 0;
29      
30      }    
31      if(days == 0)
32          printf("input error!\n");
33       else
34          printf("%d\n",days);
35 }

技术分享

判断某年某月的天数