题解 | #获得月份天数#

获得月份天数

https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6

#include <stdio.h>

int main() 
{
    int year = 0;
    int month = 0;   
    while(scanf("%d %d",&year,&month) == 2)
    {
        if(month == 1 || month == 3 || month == 5 || month == 7 || 
        month == 8 || month == 10 || month == 12)
        {
            printf("%d\n", 31);
        }
        else if(month == 4 || month == 6 || month == 9 || month == 11)
        {
             printf("%d\n", 30);
        }
        else
        {
             //判断为闰年
            if((year % 4 == 0 && year % 100 !=0) || year % 400 == 0)
            {
                printf("%d\n", 29);//闰年的2月为29天
            }
            else
            {
                printf("%d\n", 28);//平年的2月为28天
            }
           
        }
    }
    
    
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:55
点赞 评论 收藏
分享
07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务