pta 企业根据利润提成发放奖金问题 C语言

img

#include <stdio.h>
int main(){
int p;
double a;
scanf("%d",&p);

if(p<=100000){
    double a0=0.1*p;
}else if(p<200000){
    a=0.1*100000+(p-100000)*0.075;
}else if(p<400000){
    a=0.1*100000+100000*0.075+(p-200000)*0.05;
}else if(p<600000){
    a=0.1*100000+100000*0.075+200000*0.05+(p-400000)*0.03;
}else if(p<1000000){
    a=0.1*100000+100000*0.075+200000*0.05+200000*0.03+(p-6000000)*0.015;
}else{
    a=0.1*100000+100000*0.075+200000*0.05+200000*0.03+4000000*0.015+(p-10000000)*0.01;

}
printf("%.1lf",a);

return 0;

}

img

#include <stdio.h>

int main()
{
    long long profit;
    double bonus = 0.0;
    long long bands[6] = {1000000, 600000, 400000, 200000, 100000, 0};
    double rates[6] = {0.01, 0.015, 0.03, 0.05, 0.075, 0.1};
    scanf("%ld", &profit);
    for (int i = 0; i < 6; i++)
    {
        if (profit > bands[i])
        {
            bonus += (profit - bands[i]) * rates[i];
            profit = bands[i];
        }
    }
    printf("%.1lf\n", bonus);
    return 0;
}