题解 | 获得月份天数

获得月份天数

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));
    }
}

全部评论

相关推荐

求个付费实习岗位:这种就是吃满时代红利又没啥技术水平,只能靠压力学生彰显优越感的老登,别太在意了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 11:29
已编辑
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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