当前位置: 代码迷 >> 综合 >> 【1062】企业奖金问题 (C语言程序设计教程(第三版)课后习题5.8)
  详细解决方案

【1062】企业奖金问题 (C语言程序设计教程(第三版)课后习题5.8)

热度:62   发布时间:2023-12-06 09:57:13.0

switch语句:

#include <stdio.h>
int main()
{int x,i,j;scanf("%d",&x);i=x/100000;switch(i){case 10:printf("%d",j=(x-1000000)*0.01+20000);break;case 9:case 8:case 7:case 6:printf("%d",j=(x-600000)*0.015+20000);break;case 5:case 4:printf("%d",j=(x-400000)*0.03+20000);break;case 3:case 2:printf("%d",j=(x-200000)*0.05+20000);break;case 1:printf("%d",j=(x-100000)*0.75+10000);break;default :printf("%d",j=x*0.1);}return 0;
}

if语句:

#include <stdio.h>
#include <stdlib.h>int main()
{int I,J;scanf("%d",&I);if(I<=100000)J=I*0.1;else if(I<=200000)J=100000*0.1+(I-100000)*0.075;else if(I<=400000)J=100000*0.1+(200000-100000)*0.075+(I-200000)*0.05;else if(I<=600000)J=100000*0.1+(200000-100000)*0.075+(400000-200000)*0.05+(I-600000)*0.03;else if(I<=1000000)J=100000*0.1+(200000-100000)*0.075+(400000-200000)*0.05+(600000-400000)*0.03+(I-600000)*0.015;elseJ=100000*0.1+(200000-100000)*0.075+(400000-200000)*0.05+(600000-400000)*0.03+(1000000-600000)*0.015+(I-1000000)*0.01;printf("%d\n",J);return 0;
}

  相关解决方案