标签:小数 ext deb 之间 button i++ include str 1.5
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 }
标签:小数 ext deb 之间 button i++ include str 1.5
原文地址:http://www.cnblogs.com/panweiwei/p/6623590.html