|
|
发表于 2012-1-27 21:53:14
|
显示全部楼层
贴个我写的,一起学习- #include <stdio.h>
- double discount( int s );
- double total( double p, double w, double s );
- int main(){
- double p,w,s;
- printf("请输入基本运费,货物总重,距离");
- scanf("%lf%lf%lf",&p,&w,&s);
- printf("总运费=%lf\n",total(p,w,s));
- return 0;
- }
- double discount( int s ) {
- static double data[]={ 0.0, 0.02, 0.05, 0.05, 0.08, 0.08, 0.08, 0.08, 0.1, 0.1, 0.1, 0.1, 0.15 };
- if ( s>3000 ) s = 3000;
- return data[s/250];
- }
- double total( double p, double w, double s ) {
- return p*w*s*(1-discount(s));
- }
复制代码 |
|