# 经典c程序100例-2

题目

企业发放的奖金根据利润提成。利润低于或等于10万元时,奖金可提10%;
利润高于10万元,低于20万元时,低于10万元的部分按10%提成,
高于10万元的的部分,可提成7.5%;
20万到40万之间时,高于20万元的部分,可提成5%;
40万到60万之间时高于40万元的部分,可提成3%;
60万到100万之间时,高于60万元的部分,可提成1.5%,
高于100万元时,超过100万元的部分按1%提成,
从键盘输入当月利润,求应发放奖金总数?

#include <stdio.h>

int main() {
    long int profit;
    int bonus, bonus1, bonus2, bonus4, bonus6, bonus10;
    bonus1 = 10000;
    bonus2 = bonus1 + 7500;
    bonus4 = bonus2 + 10000;
    bonus6 = bonus4 + 6000;
    bonus10 = bonus6 + 6000;
    printf("请输入当月利润:");
    scanf("%ld", &profit);
    if (profit > 100000) {
        if (profit > 100000 && profit <= 200000) {
            bonus = bonus1 + (profit - 100000) * 0.075;
        } else if (profit > 200000 && profit <= 400000) {
            bonus = bonus2 + (profit - 200000) * 0.05;
        } else if (profit > 400000 && profit <= 600000) {
            bonus = bonus4 + (profit - 400000) * 0.03;
        } else if (profit > 600000 && profit <= 1000000) {
            bonus = bonus6 + (profit - 600000) * 0.015;
        } else {
            bonus = bonus10 + (profit - 1000000) * 0.01;
        }
    } else {
        bonus = bonus10 + (profit * 0.1);
    }
    printf("应发奖金为%d,\n", bonus);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

分析

对奖金进行分段,考虑每一层的奖金是上一层的奖金+这一层的提成;分段计算使调理更清晰。
时间复杂度为O(1)

上次更新时间: 2024年2月14日星期三上午10点24分