答案更加方便,最好是定义成宏
/*
【程序2】
题目:企业发放的奖金根据利润提成。利润(I)低于或等于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%提成,
从键盘输入当月利润I,
求应发放奖金总数?
1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
2.程序源代码:
main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
scanf("%ld",&i);
bonus1=100000*0.1;bonus2=bonus1+100000*0.75;
bonus4=bonus2+200000*0.5;
bonus6=bonus4+200000*0.3;
bonus10=bonus6+400000*0.15;
if(i<=100000)
bonus=i*0.1;
else if(i<=200000)
bonus=bonus1+(i-100000)*0.075;
else if(i<=400000)
bonus=bonus2+(i-200000)*0.05;
else if(i<=600000)
bonus=bonus4+(i-400000)*0.03;
else if(i<=1000000)
bonus=bonus6+(i-600000)*0.015;
else
bonus=bonus10+(i-1000000)*0.01;
printf("bonus=%d",bonus); }
==============================================================
*/
/*
【程序2】
题目:企业发放的奖金根据利润提成。利润(I)低于或等于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%提成,
从键盘输入当月利润I,
求应发放奖金总数?
[分析]
i <= 10 10%
10 < i <= 20 10% 7.5%(10-20)
20 < i <= 40 5%(20-40)
40 < i <= 60 3%(40-60)
60 < i <= 100 1.5%(60-100)
100 < i 1%(>100)
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define bonus1 (10*0.1)
#define bonus2 (bonus1+10*0.75)
#define bonus4 (bonus2+20*0.5)
#define bonus6 (bonus4+20*0.3)
#define bonus10 (bonus6+40*0.15)
int main(int argc, int **argv){
double profit = 0, bouns = 0;
printf("please enter company's profit(unit:ten thousand):\n");
scanf("%lf", &profit);
if (profit <= 10)
{
bouns = profit * 0.1;
}
else if (10 < profit <= 20)
{
bouns = bonus1 + (profit - 10) * 0.075;
}
else if (20 < profit <= 40)
{
bouns = bonus2 + (profit - 20) * 0.05;
}
else if (40 < profit <= 60)
{
bouns = bonus4 + (profit - 40) * 0.03;
}
else if (60 < profit <= 100)
{
bouns = bonus6 + (profit - 60) * 0.015;
}
else
{
bouns = bonus10 + (profit - 100) * 0.01;
}
printf("你的奖金为(万):%lf", bouns);
return 0;
}