求一个月有多少天,用switch完成。

求一个月有多少天,用switch完成。

输入格式:
输入两个整数,如2021 9,第一个表示年,第二个表示月,输出该月的天数。需要考虑闰年。如果月份错误,输出ERROR。

#include<stdio.h>
void main(){
    int year,month;
    int flag=0;
    printf("输入年月:: ");
    scanf("%d %d",&year,&month);
    if(year%4==0&&year%100!=0||year%400==0)
        flag=1; 
    switch(month){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        printf("31 天\n");
        break;
    case 2:
        if(flag==1)
            printf("29 天\n");
        else
            printf("28 天\n");
        break;
    case 4:
    case 6:
    case 9:
    case 11:
        printf("30 天\n");
        break;
    }
}