题解 | 获得月份天数

获得月份天数

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

#include <stdio.h>

short leapyear(int year)//判断是否为闰年。f=1是闰年。f=0,不是闰年
{
    short f = 0;
    if (year % 400 == 0)
        f = 1;
    if (year % 4 == 0 && year % 100 != 0)
        f = 1;
    return f;
}

int month_days(int year, int month)//返回year,month的天数
{
    int d[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (leapyear(year)) d[2] = 29;
    return d[month];
}


int main(int argc, char const* argv[])
{
    int month = 0, year = 0;
    while ((scanf("%d%d", &year, &month)) == 2)
    {
        if (month > 12 || month < 1)
        {
            printf("月份输入有误,请重新输入\n"); continue;
        }
        printf("%d\n", month_days(year, month));
    }
}

全部评论

相关推荐

03-04 07:14
门头沟学院 C++
何木健一:去啥?你能考虑去就是思想有问题,当然一周到岗一天可以考虑一下😨
点赞 评论 收藏
分享
01-12 17:45
门头沟学院 Java
985废物一枚:就是问问你能不能接受北京的房租,hr也知道公司工资不高,大概率是要贴钱的
找实习记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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