題目:企業發放的獎金根據利潤提成。利潤(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,求應發放獎金總數?
自己寫的:
include <stdio.h>
main()
{? ? int profit,percentage;? ? ? ? ? ?
printf("please enter the profit:");? ? ? ? scanf("%ld",&profit);
if(profit<=100000) ? ? percentage=profit*0.1; else if(profit<=200000) ? ? percentage=100000*0.1+(profit-100000)*0.075;? ?
else if(profit<=400000) ? ? percentage=100000*0.1+100000*0.075+(profit-200000)*0.05;
else if(profit<=600000) ? ? percentage=100000*0.1+100000*0.075+200000*0.05+(profit-400000)*0.03;
else if(profit<=1000000) ? ? percentage=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(profit-600000)*0.015; else ? ? percentage=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(profit-1000000)*0.01; printf("the percentage is %ld",percentage); return 0;
}
答案的代碼:
#include <stdio.h> main()
{?
long int i;? int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;?
scanf("%ld",&i);?
bonus1=100000*0.1;
bonus2=bonus1+100000*0.075;
bonus4=bonus2+200000*0.05;
bonus6=bonus4+200000*0.03;?
bonus10=bonus6+400000*0.015;
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);
return 0;
}