2023电子0224012郝长生

第3章第6题

#include<stdio.h>
int main()
{
    int n = 0;
    for (int year = 1000; year<= 1999; year++)
    {
        
        if ((year % 400 == 0 || year % 4 == 0 && year % 100 != 0))
        {
            printf("%d  ", year);
            n++;
        }
        if (n == 3)
        {
            printf("\n");
            n = 0;
        }
    }
    return 0;
}

 第3章第10题

#include<stdio.h>
int main()
{

    
    
    int j = 0;
    while (j < 5)
    {
        int year = 0;
        int month = 0;
        printf("请输入年份:");
        scanf_s("%d", &year);
        printf("请输入月份:");
        scanf_s("%d", &month);
        switch (month)
        {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12: printf("该月有31天"); break;
        case 2:if (year % 400 == 0 || year % 4 == 0 && year % 10 != 0) printf("该月有29天"); else printf("该天有28天"); break;
        case 4:
        case 6:
        case 9:
        case 11:
            printf("该天有30天");
            break;
        default:
            printf("月份输入错误");
                }
        j++;
        printf("\n");
    }
    return 0;
}

 第3章第24题

#include<stdio.h>
int main()
{
    for (int i = 100; i < 1000; i++)
    {
        int sum = 0;
        for (int j = 1; j < i; j++)
        {
            if (i % j == 0)
            {
                sum += j;
            }
        }
        if (sum == i)
        {
            printf("%d\n", i);
        }
    }
    return 0;
}

 第3章第28题

#include<stdio.h>
int main()
{
    double sum = 0;

    for (    double i = 1; 1.0/i > 0.00001; i++)
    {
        sum += 1 / i;
    }
    printf("%lf", sum);
    return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值