C語言 · 企業獎金髮放

來源:互聯網
上載者:User

標籤:小數   ext   deb   之間   button   i++   include   str   1.5   

演算法提高 企業獎金髮放  時間限制:1.0s   記憶體限制:512.0MB      企業發放的獎金根據利潤提成。利潤低於或等於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%提成。從鍵盤輸入當月利潤,求應發放獎金總數?(保留兩位小數)利潤的大小在double以內範例輸入210000範例輸出18000.00 作者注釋:土辦法:
 1 #include<stdio.h> 2 #include<string.h> 3 int main(){ 4     double l,j;//l:利潤;t:獎金總數。  5     scanf("%lf",&l); 6     if(l<=100000){ 7         j=l*0.1; 8     }else if(l>100000 && l<=200000){ 9         j=100000*0.1+(l-100000)*7.5/100;10         printf("%.2lf",j);11     }else if(l>200000 && l<=400000){12         j=100000*0.1+100000*7.5/100+(l-200000)*5/100;13         printf("%.2lf",j);14     }else if(l>400000 && l<=600000){15         j=100000*0.1+100000*7.5/100+200000*5/100+(l-400000)*3/100;16         printf("%.2lf",j);17     }else if(l>600000 && l<=1000000){18         j=100000*0.1+100000*7.5/100+200000*5/100+200000*3/100+(l-600000)*1.5/100;19         printf("%.2lf",j);20     }else if(l>1000000){21         j=100000*0.1+100000*7.5/100+200000*5/100+200000*3/100+400000*1.5/100+(l-1000000)*1/100;22         printf("%.2lf",j);23     }24     return 0;25 }

稍微聰明點的辦法:

 1 #include<stdio.h>   2 int main() {   3     double a;  4     scanf("%lf",&a); 5     double b = 0; 6     int s[6] = {1000000, 600000, 400000, 200000, 100000, 0};   7     double t[6] = {0.01, 0.015, 0.03, 0.05, 0.075, 0.1};   8     for(int i = 0; i < 6; i++) {   9         if(a - s[i] >= 0) {  10             b += (a - s[i]) * t[i];  11             a = s[i];12         }  13     }  14     printf("%.2lf", b);15     return 0;16 }

 

C語言 · 企業獎金髮放

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.