猜猜这个月有几天?---switch作业

117 阅读1分钟
#include <stdio.h>
int main(){

    int mouth = 1;
    int year = 1;
    printf("请输入月份:");
    scanf("%d",&mouth);
    switch (mouth){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
                printf("这个月有31天!");
                break;
        case 4:
        case 6:
        case 9:
        case 11:
                printf("这个月有30天!");
                break;
        case 2:
                printf("请输入年份:");
                scanf("%d",&year);
                if((year%4 == 0 && year%100 != 0) || year%400 != 0){
                    printf("这个月有29天!");
                } else {
                    printf("这个月有28天!");
                }
                break;
        default:
                printf("没有这个日期哦!");
                }
 }