首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C語言習題:企業利潤分級提成獎金計算

     編輯:關於C語言

提成規則表

利潤區間 (萬元)提成率備註
≤ 1010%
10 - 207.5%超過 10 萬部分
20 - 405%超過 20 萬部分
40 - 603%超過 40 萬部分
60 - 1001.5%超過 60 萬部分
> 1001%超過 100 萬部分

階梯式計算邏輯

預先計算各門檻累積獎金:

bonus1 = 100000 * 0.10;      // 10000
bonus2 = bonus1 + 100000 * 0.075;  // 17500
bonus4 = bonus2 + 200000 * 0.05;   // 27500
bonus6 = bonus4 + 200000 * 0.03;   // 33500
bonus10 = bonus6 + 400000 * 0.015; // 39500

完整程式

#include <stdio.h>

int main(void) {
    long profit;
    int bonus;
    scanf("%ld", &profit);

    if (profit <= 100000)
        bonus = profit * 0.10;
    else if (profit <= 200000)
        bonus = 10000 + (profit - 100000) * 0.075;
    else if (profit <= 400000)
        bonus = 17500 + (profit - 200000) * 0.05;
    else if (profit <= 600000)
        bonus = 27500 + (profit - 400000) * 0.03;
    else if (profit <= 1000000)
        bonus = 33500 + (profit - 600000) * 0.015;
    else
        bonus = 39500 + (profit - 1000000) * 0.01;

    printf("Bonus = %d\n", bonus);
    return 0;
}

測試案例

  • 利潤 5 萬 → 獎金 5000
  • 利潤 15 萬 → 10000 + 50000×0.075 = 13750
  • 利潤 120 萬 → 39500 + 200000×0.01 = 41500

階梯式累積計算避免重複乘法,邏輯清晰易維護。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved