zoukankan      html  css  js  c++  java
  • 奖金switch或if

    题目描述

    企业发放的奖金根据利润提成。利润低于或等于100000元的,奖金可提10%;
    利润高于100000元,低于200000元(100000<I≤200000)时,低于100000元的部分按10%提成,高于100000元的部分,可提成 7.5%;
    200000<I≤400000时,低于200000元部分仍按上述办法提成,(下同),高于200000元的部分按5%提成;
    400000<I≤600000元时,高于400000元的部分按3%提成;600000<I≤1000000时,高于600000元的部分按1.5%提成;
    I>1000000时,超过1000000元的部分按1%提成。从键盘输入当月利润I,求应发奖金总数。

    输入

    一个整数,当月利润。

    输出

    一个整数,奖金。

    样例输入

    900

    样例输出

    90

    提示

    用Switch要比用if的看起来更清晰。

    来源

    #include<stdio.h>
    int main()
    {
    int a,b;
    scanf("%d",&a);
    if(a<=100000)b=a*0.1;
    if(a>100000&&a<=200000)b=10000+(a-100000)*0.075;
    if(a>200000&&a<=400000)b=17500+(a-200000)*0.05;
    if(a>400000&&a<=600000)b=27500+(a-400000)*0.03;
    if(a>600000&&a<=1000000)b=33500+(a-600000)*0.015;
    if(a>1000000)b=39500+(a-1000000)*0.01;
    printf("%d",b);
    return 0;
    }
    或:
    #include<stdio.h>
    int main ()
    {
       int profit;
       int t;
       scanf("%d",&profit);
       t = profit/10000;
       if(t > 10)t = 10;
       switch(t)
       {
       case 0 :profit = profit * 0.1;break;
       case 1 : profit = (profit - 10000) * 0.075 + 10000;break;
       case 2 :
       case 3 : profit =(profit - 20000) * 0.05 + 17500;break;
       case 4 :
       case 5 : profit =(profit - 40000) * 0.03 + 27500;break;
       case 6 :
       case 7 :
       case 8 :
       case 9 : profit =(profit - 60000) * 0.015 + 33500;break;
       case 10 : profit =(profit - 100000) * 0.01 + 39500;break;
       }
       printf("%d",profit);
       return 0;
     
    }
  • 相关阅读:
    Java 常见异常种类
    关系型数据库和非关系型数据库的区别
    HTTP中Get与Post的区别
    经典排序算法详细总结。
    新浪实时股票数据接口http://hq.sinajs.cn/list=股票代码
    WinIo驱动级键盘模拟编程
    Logback_日志使用详解(转)
    Java_位运算(移位、位与、或、异或、非)
    算法_bitmap算法
    Selenium_IEDriver操作sendkeys输入速度太慢
  • 原文地址:https://www.cnblogs.com/SSYYGAM/p/4211093.html
Copyright © 2011-2022 走看看