第四周作业

#include <stdio.h>
#include <math.h>

int main()
{
    float a,b,c;
    float delta,realpart,imagpart,x1,x2;
    printf("请输入一元二次方程的系数:");
    scanf("%f,%f,%f",&a,&b,&c);
    if (a==0){
        printf("错误\n");
        return 1;
    }
    delta=b*b-4*a*c;
    if (delta>0){
        x1=(-b+sqrt(delta))/(2*a);
        x2=(-b-sqrt(delta))/(2*a);
        printf("方程有两个不同的实根:\n");
        printf("x1=%f\n",x1);
        printf("x2=%f\n",x2);
    }
    else if(delta==0){
        x1=-b/(2*a);
        printf("方程只有一个实根:%f",x1);
    }
    else{
            realpart=-b/(2*a);
            imagpart=delta/(2*a);
            x1=realpart+imagpart;
            x2=realpart-imagpart;
            printf("方程有两个虚根:\nx1=%f\nx2=%f",x1,x2);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>

int main()
{
    float a,b,c;
    printf("请输入三角形的三边长:");
    scanf("%f,%f,%f",&a,&b,&c);
    if(a+b<=c||a+c<=b||b+c<=a){
        printf("不能构成三角形");
        return 1;
    }
    else if(a==b&&b==c){
        printf("等边三角形\n");
    }
    else if(a==b||b==c||a==c){
        if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a){
            printf("等腰直角三角形");
        }else{
            printf("等腰三角形");
        }
    }else if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a){
        printf("直角三角形");
    }else{
        printf("一般三角形");
    }
    return 0;
}

#include <stdio.h>
#include <math.h>

int main()
{
    int data1,data2;
    char op;
    printf("please enter an expression:");
    scanf("%d%c%d",&data1,&op,&data2);
    switch(op)
    {
    case'+':
        printf("%d+%d=%d\n",data1,data2,data1+data2);
        break;
    case'-':
        printf("%d-%d=%d\n",data1,data2,data1-data2);
        break;
    case'*':
        printf("%d*%d=%d\n",data1,data2,data1*data2);
        break;
    case'/':
        if (data2==0)
            printf("错误\n");
       else
            printf("%d/%d=%d\n",data1,data2,data1/data2);
        break;
    default:
        printf("invalid operator\n");
    }
    return 0;
}

#include <stdio.h>

int main() {
    int year, month, day;
    int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int day_of_year = 0;
    printf("请输入年份、月份、日期(格式:年 月 日,用空格分隔:)");
    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;
    }
    if (is_leap_year) {
        days_in_month[1] = 29;
    }
    if (month < 1 || month > 12) {
        printf("月份输入不合法!\n");
        return 1;
    }
    if (day < 1 || day > days_in_month[month - 1]) {
        printf("日期输入不合法!\n");
        return 1;
    }
    for (int i = 0; i < month - 1; i++) {
        day_of_year += days_in_month[i];
    }
    day_of_year += day;
    printf("%d年%d月%d日 是 %d 年的第 %d 天\n", year, month, day, year, day_of_year);

    return 0;
}

#include <stdio.h>
#include <math.h>

int main() {
    int region_code;
    float weight, total_fee;
    printf("请输入目的区域编码 (0-4): ");
    scanf("%d", &region_code);
    printf("请输入邮件重量 (kg): ");
    scanf("%f", &weight);
    if (region_code < 0 || region_code > 4 || weight <= 0) {
        printf("无效的输入,请检查区域编码和重量。\n");
        return 1;
    }
    float base_fee, extra_fee_per_kg;
    if (region_code == 0) {
        base_fee = 10;
        extra_fee_per_kg = 3;
    } else if (region_code == 1) {
        base_fee = 10;
        extra_fee_per_kg = 4;} 
    else {
        base_fee = 15;
        if (region_code == 2) {
            extra_fee_per_kg = 5;
        } else if (region_code == 3) {
            extra_fee_per_kg = 6.5;
        } else {  // region_code == 4
            extra_fee_per_kg = 10;
        }
    }
    float extra_weight = weight - 1;
    if (extra_weight > 0) {
        extra_weight = ceil(extra_weight);  // 不足1kg按1kg计算
    } else {
        extra_weight = 0;  // 重量 ≤1kg,无续重
    }
    total_fee = base_fee + extra_weight * extra_fee_per_kg;
    printf("总运费为: %.2f 元\n", total_fee);
    return 0;
}

#include <stdio.h>

int main() {
    double profit, bonus = 0.0;
    printf("请输入当月利润(单位:万元):");
    scanf("%lf", &profit);
    if (profit <= 10) {
        bonus = profit * 0.1;
    } else if (profit <= 20) {
        bonus = 10 * 0.1 + (profit - 10) * 0.075;
    } else if (profit <= 40) {
        bonus = 10 * 0.1 + 10 * 0.075 + (profit - 20) * 0.05;
    } else if (profit <= 60) {
        bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (profit - 40) * 0.03;
    } else if (profit <= 100) {
        bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (profit - 60) * 0.015;
    } else {
        bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (profit - 100) * 0.01;
    }
    printf("应发奖金总数为:%.2f 万元\n", bonus);

    return 0;
}

#include <stdio.h>

int main() {
    double profit, bonus = 0.0;
    int range;
    printf("请输入当月利润(单位:万元):");
    scanf("%lf", &profit);
    if (profit <= 10) {
        range = 0;
    } else if (profit <= 20) {
        range = 1;
    } else if (profit <= 40) {
        range = 2;
    } else if (profit <= 60) {
        range = 3;
    } else if (profit <= 100) {
        range = 4;
    } else {
        range = 5;
    }
    switch(range) {
        case 0:
            bonus = profit * 0.1;
            break;
        case 1:
            bonus = 10 * 0.1 + (profit - 10) * 0.075;
            break;
        case 2:
            bonus = 10 * 0.1 + 10 * 0.075 + (profit - 20) * 0.05;
            break;
        case 3:
            bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (profit - 40) * 0.03;
            break;
        case 4:
            bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (profit - 60) * 0.015;
            break;
        case 5:
            bonus = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (profit - 100) * 0.01;
            break;
        default:
            printf("无效的利润区间。\n");
            return 1;
    }
    printf("应发奖金总数为:%.2f 万元\n", bonus);

    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值