Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

用C语言编程完成下面问题

  1. User

    用C语言编程完成下面问题

  2. Assistant

    这是一个问答性质的问题,请提供问题的具体内容。

  3. User

    用C语言编程完成下面问题 题目叙述:给你一个年份和月份,求该月有多少天 输入:一个年份(正整数),一个月份(1-12),中间有一个空格隔开 输出:该月的天数,单独占一行。 样例输入Copy:2012 2 样例输出Copy:29

  4. Assistant

    以下是C语言代码实现:

    #include <stdio.h>
    
    int main()
    {
        int year, month, days;
    
        // 输入年份和月份
        printf("请输入年份和月份(用空格隔开):");
        scanf("%d %d", &year, &month);
    
        // 计算该月的天数
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                days = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28;
                break;
            default:
                printf("输入的月份不正确!\n");
                return 1;
        }
    
        // 输出该月的天数
        printf("%d年%d月有%d天。\n", year, month, days);
    
        return 0;
    }
    

    代码实现思路是根据输入的月份,分别计算该月有多少天。对于闰年的情况,需要特别处理。最后输出计算得到的天数即可。

  5. User

    用C语言编程完成下面问题

    题目叙述:给你一个年份和月份,求该月有多少天

    输入:一个年份(正整数),一个月份(1-12),中间有一个空格隔开

    输出:该月的天数,单独占一行。

    样例输入Copy:2012 2

    样例输出Copy:29

  6. Assistant

    以下是C语言代码实现:

    #include <stdio.h>
    
    int main()
    {
        int year, month, days;
    
        // 输入年份和月份
        printf("请输入年份和月份(用空格隔开):");
        scanf("%d %d", &year, &month);
    
        // 计算该月的天数
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                days = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28;
                break;
            default:
                printf("输入的月份不正确!\n");
                return 1;
        }
    
        // 输出该月的天数
        printf("%d年%d月有%d天。\n", year, month, days);
    
        return 0;
    }
    

    代码实现思路是根据输入的月份,分别计算该月有多少天。对于闰年的情况,需要特别处理。最后输出计算得到的天数即可。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.