思路:
1、需要考虑平年(2月份28)和闰年(2月份29)
2、1,3,5,7,8,10,12月 --31天 利用switch穿透来写
3、其他的月份都是30天
#include<stdio.h>
void main(){
/*根据输入的月份和年份,求出该月的天数(1-12)*/
//需要考虑平年(2月份28)和闰年(2月份29)
//1,3,5,7,8,10,12月 --31天
//其他的月份都是30天
int year,month;
printf("请输入年份:");
scanf("%d",&year);
printf("请输入月份:");
scanf("%d",&month);
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("%d年的%d月是%d",year,month,31);
break;
case 2:
//判断year是平年还是闰年
if((year % 4 == 0 && year % 100 !=0)||year % 400 == 0){
printf("%d年的%d月是%d天",year,month,29); //润年29天
}else{
printf("%d年的%d月是%d天",year,month,28);//平年28天
}
break;
default:
printf("%d年的%d月是%d天",year,month,30);
}
getchar();
getchar();
}