C基础学习(24.7.12)第三天

最后一题,将三个数从小到大依次存储到abc中,最后结果是a<b<c。你们的数据可以从终端获取 

 第一题:

#include <stdio.h>
int main() 
{
    int a;
    printf("输入三位整数\n");
    scanf("%d", &a);
    int i,j,k;
    k = a % 100;
    j = (a / 100) % 10;
    i = a / 100;
    printf("个位+百位+百位的和为%d\n",i+j+k);
    return 0;
}

 第二题:

#include <stdio.h>
#include <math.h>
int main() {
    double a, b, c;
    printf("输入三角形的三条边长 a, b, c:\n");
    scanf("%lf %lf %lf", &a, &b, &c);
    double p = (a + b + c) / 2;
    double area = sqrt(p * (p - a) * (p - b) * (p - c));
    printf("三角形的面积为: %lf\n", area);
    return 0;
}

 

 第三题:

#include <stdio.h>
int main() {
    int year;
    printf("请输入一个年份: ");
    scanf("%d", &year);
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
        printf("%d 年是闰年。\n", year);
    } else {
        printf("%d 年不是闰年。\n", year);
    }
    return 0;
}

第四题

#include <stdio.h>
int main() {
    int year ;
    int month;
    int day ;
    printf("输入年 月 日\n");
    int day_count = 0;
    scanf("%d %d %d", &year, &month, &day);
    // 判断是否是闰年
    int is_leap_year = 0;
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
        is_leap_year = 1;
    }
    // 累加前面所有月份的天数
    for (int m = 1; m < month; m++) {
        if (m == 2) {
            if (is_leap_year) {
                day_count += 29;
            } else {
                day_count += 28;
            }
        } else if (m == 4 || m == 6 || m == 9 || m == 11) {
            day_count += 30;
        } else {
            day_count += 31;
        }
    }
    // 加上当前月份的天数
    day_count += day;
    printf("%d年%d月%d日是这一年的第%d天\n", year, month, day, day_count);
    return 0;
}

 

第五题

#include<stdio.h>
 
int main()
{
 int a, b, c;
    int temp;
    printf("请输入3个数:\n");
    scanf("%d%d%d", &a, &b, &c);
    printf("输入的数是:a=%d,b=%d,c=%d\n", a, b, c);
    if (a > b) {
        int temp = a;//交换a和b的值
        a = b;
        b = temp;
    }
    if (b > c) {
        int temp = b;//交换b和c的值
        b = c;
        c = temp;
    }
    if (a > b) {
        int temp = a;//交换a和b的值
        a = b;
        b = temp;
    }
    printf("从小到大排序后:\n");
    printf("a=%d,b=%d,c=%d\n", a, b, c);
    return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值