(1)用if语句编程序:
#include#define M 100000 int main(){ int a; float b;//a代表利润,b代表奖金 printf("请输入当月利润:n"); scanf("%d",&a); if(a>M){ if(a>2*M){ if(a>4*M){ if(a>6*M){ if(a>10*M){ b=M*0.1+M*0.075+2*M*0.05+2*M*0.03+4*M*0.015+(a-10*M)*0.01; } else{ b=M*0.1+M*0.075+2*M*0.05+2*M*0.03+(a-6*M)*0.015; } } else{ b=M*0.1+M*0.075+2*M*0.05+(a-4*M)*0.03; } } else{ b=M*0.1+M*0.075+(a-2*M)*0.05; } } else{ b=M*0.1+(a-M)*0.075; } } else{ b=a*0.1; } printf("奖金为:%0.2f",b); }
(2)switch语句:
#include#define M 100000 int main(){ int a,b; float c;//a代表利润,c代表奖金 printf("请输入当月利润:n"); scanf("%d",&a); b=a/M; if(a/M>10){ b=10; } switch(b){ case 0:c=a*0.1;break; case 1:c=M*0.1+(a-M)*0.075;break; case 2: case 3:c=M*0.1+M*0.075+(a-M)*0.05;break; case 4: case 5:c=M*0.1+M*0.075+2*M*0.05+(a-4*M)*0.03;break; case 6: case 7: case 8: case 9:c=M*0.1+M*0.075+2*M*0.05+2*M*0.03+(a-6*M)*0.015;break; case 10:c=M*0.1+M*0.075+2*M*0.05+2*M*0.03+4*M*0.015+(a-10*M)*0.01;break; } printf("奖金为:%0.2f",c); }



