从键盘输入某年某月(包括闰年),用switch语句编程输出该年的该月拥有的天数。要求考虑闰年以及月份不在合法范围内的情况。已知闰年的2月有29天,平年的2月有28天
1 #include<stdio.h> 2 int main() 3 { 4 int year,month; 5 printf("请输入年和月:\n"); 6 scanf("%d%d",&year,&month); 7 if(year%4==0&&year%100!=0||year%400==0) 8 switch(month) 9 { 10 case 1: 11 case 3: 12 case 5: 13 case 7: 14 case 8: 15 case 10: 16 case 12:printf("该月有31天\n");break; 17 case 2:printf("该月有29天\n");break; 18 case 4: 19 case 6: 20 case 9: 21 case 11:printf("该月有30天\n");break; 22 } 23 else 24 switch(month) 25 { 26 case 1: 27 case 3: 28 case 5: 29 case 7: 30 case 8: 31 case 10: 32 case 12:printf("该月有31天\n");break; 33 case 2:printf("该月有28天\n");break; 34 case 4: 35 case 6: 36 case 9: 37 case 11:printf("该月有30天\n");break; 38 } 39 return 0; 40 }